sorting and reversing lines of a file

Root Boy Jim rbj at nav.icst.nbs.gov
Wed Mar 15 03:03:40 AEST 1989


? From: Francois-Michel Lang <lang at pearl.prc.unisys.com>

? I need utilities to do two things:
? (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 don't want to do this, but it does work!

sed -e '1{;h;d;}' -e '$!{;G;h;d;}' -e '$G'

Well, up to a point anyway. An `ls -l /etc | wc -l' produces 140 lines
on our system. Piping the ls to the sed command produced only about 70
lines, giving a total of 4000 characters. That seems to be the limit.

Don't forget to quote the `!' if using csh.  The semicolons are an
undocumented feature.  An awk script would be a better way to do this.
Tail -r seems to be the best buggestion unless you are reversing
really BIG files. In that case you probably do want to write a C
program. There's just no escaping the buffering problem.

	Catman Rshd <rbj at nav.icst.nbs.gov>
	Author of "The Daemonic Versions"



More information about the Comp.unix.questions mailing list