Reversing a file?

Dirk Pellett dlp at gistdev.UUCP
Wed Oct 4 20:11:10 AEST 1989


>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:

itkin at mrspoc.Transact.COM (Steven M. List) replies:
>This uses one of my all-time favorite VI/EX commands, and this is the
>first time I can remember anyone ASKING for it:
>	echo "g/./.m0\nw $OUTPUT\nq" | ex $INPUT
>the "g/./.m0" marks every line in the file and then moves each marked
>line to the beginning of the file (after line zero).

Actually, it marks all lines except blank lines.  What you really want is
the following:
        echo 'g/^/m0
        w
        q' | ed $1
That way you won't end up will a ton of blank lines at the end of your file.
-- 
-- 
Dirk Pellett			uunet!gistdev!dlp



More information about the Comp.unix.questions mailing list