Reversing a file?
Jean-Pierre Radley
jpr at dasys1.UUCP
Fri Oct 13 05:01:24 AEST 1989
In article <MONTNARO.89Oct2224215 at sprite.crd.ge.com> <montanaro at crdgw1.ge.com> (Skip Montanaro) writes:
>Does somebody have an elegant shell script for reversing the lines of a
>file? I've come up with the following short one:
I don't think I made this up. Maybe I got it from Kernighan & Pike.
But it does seem simpler than the answers I've seen posted to date,
if you don't have 'tail -r', and if the file isn't too big (whatever that
may be, but at some point awk runs out of space).
<file awk '
{ line[i++] = $0 }
END { while (i--) print line[i] }
'
--
Jean-Pierre Radley jpr at jpradley.uucp
New York, NY 72160.1341 at compuserve.com
More information about the Comp.unix.questions
mailing list