Reversing a file?
Randal Schwartz
merlyn at iwarp.intel.com
Sat Oct 7 01:28:46 AEST 1989
In article <1989Oct3.201759.19182 at mrspoc.Transact.COM>, itkin at mrspoc (Steven M. List) writes:
| 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
|
Arrgh. Both of those fail on *blank* lines. (They'll all end up at
either the beginning or the end... I'm too tired to figure out which.)
Try:
echo "g/^/m0|w $OUTPUT|q" | ex $INPUT
instead.
Just another 'ex' hacker,
--
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/
More information about the Comp.unix.questions
mailing list