Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seeking a file

Status
Not open for further replies.

yumbelie

Programmer
Dec 31, 2002
96
GB
Hi,
I'm looking for a way to get to the end of a text file, so I can read the last line in to extract some pertinent information. Unfortunatly, I can't read the entire text file into an an array and perform the operations in memory, because the textfiles contain 5-6 million lines - typically.

Basically, the format of the file (awkwardly), is that there is pertinent information on the top line, and the last line, and then the millions of records populate the in-between:


CUST NAME: Joe Blogs, DATA: data, DATA: data (First Line)
001, 1234, 5678 (Records)
002, 1234, 5678
003, 1234, 5678
004, 1234, 5678
...--->to infinity & beyond!
CUST ACCNT: 99199299 CUST PREFIX: BSN211 (Last Line - Format varies)


I want to seek to the line prior to EOF being true, so I can pull out the value, reset the position in the file to the first line, and continue parsing. It would also be good if the current line I am processing could be checked against the files last line, e.g. CurrentLine = 10 LastLine = 151 so that I don't have to A) right a bunch of statements to test the contents of each line to determine if it's the last one and B) so I don't accidentally process the last line using the standard record processing (which would produce garbage).

In a nutshell, I know where the data is, I know what format it will typically arrive in, I just can't figure out how to reach it easily.

Thanks for any help.

Yum.
 
You can seek relative to the end of the file - like so...

seek #fileno, lof(#fileno) - 2048

That should put you 2K before the end of the file - so now you can array from there, then use the last line.

Hope that helps.

mmilan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top