sorting and reversing lines of a file

J.L.WOOD jlw at lznv.ATT.COM
Mon Jan 30 02:13:39 AEST 1989


In article <9056 at burdvax.PRC.Unisys.COM>, lang at pearl.PRC.Unisys.COM (Francois-Michel Lang) writes:
> 
> 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.
> 
>     E.g., if the file "f" contains
>        line1 
>        line2
>        line3
>     I want to produce
>        line 3
>        line 2
>        line 1

Try good ol' ed:

ed a
a
line1
line2
line3
.
,p
line1
line2
line3
g/^/m0
,p
line3
line2
line1
Q

Could anything be easier.  The operative line is g/^/m0.
Ie first mark all lines and then one at a time move them
to follow line zero.

Joe Wood
jlw at lznv.ATT.COM



More information about the Comp.unix.questions mailing list