Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ASCII File - file access - reverse order

ASCII File - file access - reverse order

ASCII File - file access - reverse order

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?

RE: ASCII File - file access - reverse order

Maybe, if file is not that big, copy it into queue(n,line) and sort reverse or sort file with external program.

RE: ASCII File - file access - reverse order

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

RE: ASCII File - file access - reverse order

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

RE: ASCII File - file access - reverse order

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.

RE: ASCII File - file access - reverse order

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close