shell pipeline to reverse the order of lines.

Steven M. List itkin at mrspoc.Transact.COM
Thu Feb 28 10:20:14 AEST 1991


vojta at powdermilk.berkeley.edu (Paul Vojta) writes:

>In article <1991Feb26.025903.5850 at NCoast.ORG> allbery at 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 at 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 at Transact.COM                                 :



More information about the Alt.sources.d mailing list