Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucsd!ogccse!littlei!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Reversing a file? Message-ID: <5019@omepd.UUCP> Date: 6 Oct 89 15:28:46 GMT References: <1989Oct3.201759.19182@mrspoc.Transact.COM> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 37 In-reply-to: itkin@mrspoc.Transact.COM (Steven M. List) In article <1989Oct3.201759.19182@mrspoc.Transact.COM>, itkin@mrspoc (Steven M. List) writes: | 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 | 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@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/