Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!rutgers!att!lznv!jlw From: jlw@lznv.ATT.COM (J.L.WOOD) Newsgroups: comp.unix.questions Subject: Re: sorting and reversing lines of a file Summary: use ed Keywords: sort reverse Message-ID: <1541@lznv.ATT.COM> Date: 29 Jan 89 16:13:39 GMT References: <9056@burdvax.PRC.Unisys.COM> Organization: AT&T ISL Lincroft NJ USA Lines: 41 In article <9056@burdvax.PRC.Unisys.COM>, lang@pearl.PRC.Unisys.COM (Francois-Michel Lang) writes: > > I need utilities to do two things: > (1) reverse the order of lines in a file > but leave the lines themselves intact. > The Unix utility does just the opposite of this. > > E.g., if the file "f" contains > line1 > line2 > line3 > I want to produce > line 3 > line 2 > line 1 Try good ol' ed: ed a a line1 line2 line3 . ,p line1 line2 line3 g/^/m0 ,p line3 line2 line1 Q Could anything be easier. The operative line is g/^/m0. Ie first mark all lines and then one at a time move them to follow line zero. Joe Wood jlw@lznv.ATT.COM