: What is the best way to read text lines backwards
: from a text file? I am trying to avoid writing
: some kind of buffer management support so that I
: can seek forward and backward in a text file by line.
Awk (or perl) is your friend, me thinks. The AWK script:
{ Buf[NR] = $0 }
END { for (i = NR; i > 0; i--)
print Buf[i]
}
prints out its input in reverse order. This does mean, however,
that the entire file is buffered in memory. Don't try it with
files that are much larger then your machines memory.
Hope this helps,
Ruurd.
--
========================================================================
Ruurd Beerstra, CMG-IT, Netherlands. | #include <stddisclaimer.h>
| what is he doing on my hard disk?