Reversing a file?
Conor P. Cahill
cpcahil at virtech.UUCP
Wed Oct 4 03:55:23 AEST 1989
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? I've come up with the following short one:
How about the following pipeline:
grep -n "\$" t.c | sort -rn | sed "s/^[0-9]*://"
what this does is as follows:
grep - get all lines of the file and number them
sort - key is numeric and sort in reverse order
sed - remove line numbers added by grep
Good luck.
--
+-----------------------------------------------------------------------+
| Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 !
| Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 |
+-----------------------------------------------------------------------+
More information about the Comp.unix.questions
mailing list