Possible Duplicate:
How would you implement tail efficiently?
A friend of mine was asked how he'd implement tail -n
.
To be clear, we are required to print the last n
lines of the file specified.
I thought of using an array of n strings and overwriting them in a cyclic manner.
But if we are given, say a 10 GB
file, this approach doesn't scale at all.
Is there a better way to do this?