Reversing a file?
Steven M. List
itkin at mrspoc.Transact.COM
Wed Oct 4 06:17:59 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:
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). The "w $OUTPUT"
will either write the reversed file to a new file or overwrite the
original file, depending on whether or not OUTPUT is valued.
For those of us who DON'T have "tail -r", this works great! From within
VI, you can use the same global command:
:g/./.m0
--
+----------------------------------------------------------------------------+
: Steven List @ Transact Software, Inc. :^>~ :
: Chairman, Unify User Group of Northern California :
: {apple,coherent,limbo,mips,pyramid,ubvax}!itkin at guinan.Transact.COM :
More information about the Comp.unix.questions
mailing list