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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASCII File - file access - reverse order

Status
Not open for further replies.

Khartoum

Programmer
Jun 30, 2012
11
AU
I have a need to read a large ascii file in reverse order, that is to find EOF then read the last line, then the penultimate line and so on. Under normal circumstances, I would use a 'PREVIOUS' command, but of course this is not available for ASCII files.

A brute force approach is to find the file pointer for the last record, then sequentially GET(ascii,fielponter). It works, but is slow when having to find EOF each time.

Any ideas anybody?
 
Maybe, if file is not that big, copy it into queue(n,line) and sort reverse or sort file with external program.
 
Thanks for your reply Uniglass. Your suggestion is better than I have come up with so far.
My problem is that I have to read the last few 'lines' of an ASCII based log file that is generated every five seconds on a daily basis by a hardware based unit. Towards the end of the day' there are up to 15,000 lines and I need to generate a 'real time' display of current (latest) data. This is not necessarily the 'last line' as each line represents a different 'time slice' of multiple subjects. I need to parse through the last 'few minutes' of time and extract the latest data for each subject. Hence my problem! It is so wasteful to have to loop through the entire file, particularly towards the end of the day when the file size is getting quite large. In the ned, it may be the only option left, but is not 'elegant'!

Best regards
 
Maybe the same way you did it but for me it looks fast enough because it skips lines already processed.
( force QUICKSCAN driver option, default is off when not read only for others )

1. Start from begining of the file and copy to queue intil EOF, save filepointer, reverse queue, process
2. SET(file, filepointer) , loop until eof , copy to queue intil EOF, save pointer, reverse queue, process
3. step 2
 
Thanks again for taking the time to respond, much appreciated.

I'll give your suggestion a go and see what happens. Might take me a day or two to sort it out, but will definitely let ypu know how I get on. :)

Thanks again.
 
I THINK I have solved the problem.
I tried various ways with the current methods as you suggested, without real success. Too many errors and issues, unwieldy, inelegant. So I looked in the Clarion Templates (ABASCII.CLW and ABASCII.INC) and duplicated the 'NEXT' file class, renamed it PREVIOUS, changed the line Cnt+=(CHOOSE(SELF.FindDirection= 'Down',1,-1)) to Cnt-=(Choose(SELF.Find.Direction= 'Up',1,-1)) and now 'PREVIOUS' works a treat.
It is so simple, I can't believe it and why didn't Topspeed do the same thing? There must be a reason for such a simple 'fix' not being in the original template for ASCII files. I am now looking for hidden 'fish hooks' because I just cant't believe it is so simple but, so far, the only possible problem I have found is error handling IF beginning of file is reached. (Fixed in calling code by BREAK if record number <1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top