Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Reading line by line in a large text file

Reply
Thread Tools

Reading line by line in a large text file

 
 
xyz
Guest
Posts: n/a
 
      06-09-2008
Hi,
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line
and when i read for the next time , my program shuld read only second
line discarding first line..

i did it with ignore function but it is taking lot of time to reach
end of file...

please give me a simple approch to do this..

thanks to all
 
Reply With Quote
 
 
 
 
Lars Uffmann
Guest
Posts: n/a
 
      06-09-2008
xyz wrote:
> I have a text file around 7GB includes 100 million lines...
> I want to read the data line by line when I approach my module..
>
> ie., when i read for the first time , my program shuld read only one
> line and when i read for the next time , my program shuld read only
> second line discarding first line..


I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:
http://www.cplusplus.com/reference/c...dio/ftell.html


Best Regards,

Lars
 
Reply With Quote
 
 
 
 
xyz
Guest
Posts: n/a
 
      06-09-2008
On Jun 9, 2:09*pm, Lars Uffmann <(E-Mail Removed)> wrote:
> xyz wrote:
> > I have a text file around 7GB includes 100 million lines...
> > I want to read the data line by line when I approach my module..

>
> > ie., when i read for the first time , my program shuld read only one
> > line and when i read for the next time , my program shuld read only
> > second line discarding first line..

>
> I'm not sure what you mean by "first time" and "next time" - do you mean
> subsequent read calls with the open file, or do you mean reading a line,
> closing the file, then opening it again and now reading the 2nd line?
>
> In the first case, I don't see the problem, because you just read one
> line after another.
>
> In the second case, you'll need to store a filepointer somewhere
> (variable or config file) - to the position AFTER your last read (i.e.
> the first byte of the succeeding line). Then when you re-open the text
> file, just jump to that file pointer and continue reading.
>
> For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/c...dio/ftell.html
>
> Best Regards,
>
> * *Lars


What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details
 
Reply With Quote
 
xyz
Guest
Posts: n/a
 
      06-09-2008
On Jun 9, 2:17*pm, xyz <(E-Mail Removed)> wrote:
> On Jun 9, 2:09*pm, Lars Uffmann <(E-Mail Removed)> wrote:
>
>
>
> > xyz wrote:
> > > I have a text file around 7GB includes 100 million lines...
> > > I want to read the data line by line when I approach my module..

>
> > > ie., when i read for the first time , my program shuld read only one
> > > line and when i read for the next time , my program shuld read only
> > > second line discarding first line..

>
> > I'm not sure what you mean by "first time" and "next time" - do you mean
> > subsequent read calls with the open file, or do you mean reading a line,
> > closing the file, then opening it again and now reading the 2nd line?

>
> > In the first case, I don't see the problem, because you just read one
> > line after another.

>
> > In the second case, you'll need to store a filepointer somewhere
> > (variable or config file) - to the position AFTER your last read (i.e.
> > the first byte of the succeeding line). Then when you re-open the text
> > file, just jump to that file pointer and continue reading.

>
> > For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/c...dio/ftell.html

>
> > Best Regards,

>
> > * *Lars

>
> What i mean is....i want the second case...
> i tried storing the file positon after reading the line...
> but i couldnt succeed...
> could you please get some more details


i got it...thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading LAST line from text file without iterating through the file? Robin Wenger Java 191 03-26-2011 06:19 PM
help in reading a large text file using verilog.... alangs VHDL 0 07-22-2010 07:28 AM
reading a line by line from local text file through WATIR curious Ruby 1 10-25-2006 01:34 PM
How to read a text file line by line and remove some line kaushikshome C++ 4 09-10-2006 10:12 PM
reading the DB vs. reading a text file...performance preference? Darrel ASP .Net 3 11-11-2004 02:27 PM



Advertisments