Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!mrspoc!itkin From: itkin@mrspoc.Transact.COM (Steven M. List) Newsgroups: comp.unix.questions Subject: Re: Reversing a file? Message-ID: <1989Oct3.201759.19182@mrspoc.Transact.COM> Date: 3 Oct 89 20:17:59 GMT References:Reply-To: itkin@guinan.UUCP (Steven List) Organization: Transact Software, Inc. Lines: 26 montnaro@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@guinan.Transact.COM :