By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

Skip lines in txt-file

P: n/a
I have to process large files containing "logical" blocks of strings, each
block varying in number of lines.
....
Block number x
string1
string2
....
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!
TIA
Pjotr
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Pjotr Wedersteers" <x3****@westerterp.com> wrote in message news:<41***********************@news.xs4all.nl>...
I cannot guarantee (unfortunately) the file is still open, so the file


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...
Jul 17 '05 #2

P: n/a
"Pjotr Wedersteers" <x3****@westerterp.com> wrote in message
news:<41***********************@news.xs4all.nl>...

What is the fastest way to skip those first <$index -1> lines
the next read ?


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.

Cheers,
NC
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.