Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!gistdev!dlp From: dlp@gistdev.UUCP (Dirk Pellett) Newsgroups: comp.unix.questions Subject: Re: Reversing a file? Message-ID: <816@gistdev.UUCP> Date: 4 Oct 89 10:11:10 GMT References: <1989Oct3.201759.19182@mrspoc.Transact.COM> Organization: Global Information Systems Technology Inc., Savoy, IL Lines: 20 >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: itkin@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