sorting and reversing lines of a file

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Jan 27 09:45:44 AEST 1989


In article <9056 at burdvax.PRC.Unisys.COM> lang at pearl.PRC.Unisys.COM (Francois-Michel Lang) writes:
>(1) reverse the order of lines in a file
>    but leave the lines themselves intact.
>    The Unix utility does just the opposite of this.

You mean it doesn't leave the lines intact or it doesn't reverse their order?
Which utility?

Anyway, check for the existence of a "rev" utility on your system.
It's standard on all Research UNIXes I know of, including 4BSD, but
not on UNIX System V.

On a SVID-conformant system, make yourself a shell function or script
that does:

	pr -n9 -t | sort +0nr -1 | cut -f2-

Sorting isn't the most efficient way to do this task, but it's easy
to implement this way.  If you have a LOT of file reversing to do,
then probably a real software engineering task should be undertaken.



More information about the Comp.unix.questions mailing list