C
Chris Nestrud
I need to read a number of lines from the end of a large file. For
example, the file may have 460484 lines and I need the last 500.
The "tail -500 file" command from the shell works, but I'd like a solution
that doesn't involve calling an external program.
Reading the file and keeping an array with the last 500 lines seen
works, but takes a very long time on large files.
I've looked at the seek function, but other than guessing at how far
from EOF to seek backward, I can't figure out how to make sure that I'm
left with enough data to account for the needed number of lines.
Any suggestions or other approaches would be much appreciated.
example, the file may have 460484 lines and I need the last 500.
The "tail -500 file" command from the shell works, but I'd like a solution
that doesn't involve calling an external program.
Reading the file and keeping an array with the last 500 lines seen
works, but takes a very long time on large files.
I've looked at the seek function, but other than guessing at how far
from EOF to seek backward, I can't figure out how to make sure that I'm
left with enough data to account for the needed number of lines.
Any suggestions or other approaches would be much appreciated.