Skip lines in txt-file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have to process large files containing "logical" blocks of strings, each
block varying in number of lines.
Block number x
string n
Block number y
et cetera.

Blocks are read and processed one by one. My GetNextBlock ($index) function
returns an array with all lines in a block, and returns the line number of
the next block header.
What is the fastest way to skip those first <$index -1> lines the next read
? I cannot guarantee (unfortunately) the file is still open, so the file
pointer must be assumed at start of file again.
I had an intermittent solution in which I first split all the blocks into
separate files, but that caused a lot of other unwanted effects beyond the
scope of this posting.

Hints, pointers appreciated!

Re: Skip lines in txt-file

Quoted text here. Click to load it

Why not?
If you open it, it's going to remain open until you close it...

Just how big is this file?
Could you not process all blocks on initial opening?

If it is closed between reads (not processing all at once):
is the file being modified when closed?
you could perhaps keep track of what position in file you're at.
Or on the 1st pass through... locate starting position of all blocks...

Re: Skip lines in txt-file

Quoted text here. Click to load it

Read the whole file into an array via file() and access the desired
line by number.  The array could then be serialized and written into
a session variable to get rid of additional reads of the file.


Site Timeline