Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Skip lines in txt-file
- Pjotr Wedersteers
October 11, 2004, 3:54 pm
rate this thread
block varying in number of lines.
Block number x
Block number y
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
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...
- Nikolai Chuvakhin
October 11, 2004, 10:21 pm