Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!agate!apple!mrspoc!itkin From: itkin@mrspoc.Transact.COM (Steven M. List) Newsgroups: alt.sources.d Subject: Re: shell pipeline to reverse the order of lines. Message-ID: <1991Feb27.232014.19351@mrspoc.Transact.COM> Date: 27 Feb 91 23:20:14 GMT References: <3*-&S|^@rpi.edu> <2166@m1.cs.man.ac.uk> <1991Feb26.025903.5850@NCoast.ORG> <1991Feb27.010612.25618@agate.berkeley.edu> Reply-To: steven@Transact.COM Organization: Transact Software Lines: 41 vojta@powdermilk.berkeley.edu (Paul Vojta) writes: >In article <1991Feb26.025903.5850@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes: >> >>I don't understand what's wrong with >> >> nl | sort -nr | cut -f2- > >What's wrong with > > tail -r > >Or is that too simple? > >--Paul Vojta, vojta@math.berkeley.edu Berkeley BSD bigot! %^} Not all systems HAVE tail -r!! Particularly not System V and derivatives. But here's my favorite way to do it in ed/ex/vi: :g/./.m0 so if you're already in VI, then you just use this command. You can embed it as a HERE file in a shell script for ed, too. Just for interest, a friend wrote an Emacs macro to reverse the characters in each line. I did the same in AWK: awk 'BEGIN { new="" } { new=""; j = length for (i=length;i>0;i--) new=new substr($0,i,1) print new}' If you combine the two, you have effectively reversed the entire file! -- +----------------------------------------------------------------------------+ : Steven List @ Transact Software, Inc. :^>~ : : Chairman, Unify User Group of Northern California : : itkin@Transact.COM :