Reversing a file?

Randal Schwartz merlyn at iwarp.intel.com
Fri Oct 6 00:59:42 AEST 1989


In article <2283 at munnari.oz.au>, ok at cs (Richard O'Keefe) writes:
| In article <MONTNARO.89Oct2224215 at sprite.crd.ge.com>, montnaro at sprite.crd.ge.com (Skip Montanaro) writes:
| >Does somebody have an elegant shell script for reversing the lines of a file?
| In BSD systems:
| 	cat -n $* | sort -nr | sed -e 's/^.......//'
| In System V:
| 	pr -t -n6 $* | sort -nr | cut -f2-

In Perl, of course, it's

perl -e 'unshift(a,$_) while (<STDIN>); print @a;'

which works even when 'tail -r' (another solution in another post)
doesn't, provided you have the real/virtual memory to spare.

Just another Perl hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list