Page 1 of 1

How to read a text file in chunks.. 100 lines at a time (\n)

Posted: Thu Feb 11, 2010 1:03 am
by vexus
I have tried numerous different codes and I keep failing at doing this.

Say I have a large text file, each line contains valuable data..so I can't just do a fgets and set a certain amount of data to read because I am not sure on each lines length so some times the data would get cut off and not processed correctly so I need to read it line by line.


The problem is processing each piece of data line by line is way to slow. So i thought if I read say 100 lines at once as a chunk and then processed that chunk of 100 items of data it would speed things up by a lot!


Please some one help me!

Re: How to read a text file in chunks.. 100 lines at a time (\n)

Posted: Thu Feb 11, 2010 12:43 pm
by vexus
If you guys need a little bit of clarification.


say I have a text file with

Nick
Bob
John
Larry
Ashley
Britney
Tom
Lisa
Joshua

Say I need to process that list 2 lines at a time.

First chunk [Nick,Bob]
Second chunk [John,Larry]
Third chunk [Ashley,Britney]

Does anyone have the slightest idea of how to accomplish that?

Re: How to read a text file in chunks.. 100 lines at a time (\n)

Posted: Thu Feb 11, 2010 2:32 pm
by AbraCadaver
Depends upon what you mean by "process" the lines. What are you doing with them?