How to sort on right most column

David W. Tamkin dattier at vpnet.chi.il.us
Fri May 24 09:34:43 AEST 1991


jpr at jpradley.jpr.com (Jean-Pierre Radley) wrote in
<1991May22.191522.19709 at jpradley.jpr.com>:

| >From the keyboard of felps at convex.com (Robert Felps):
| >:I don't know of any way to sort based on right to left. But you might try


| With awk, $NF is the last field. So pipe the file through awk, prepending
| the last field ($NF) to the whole line ($0), separated by something wierd,
| say ^B. Pipe this to sort, then pipe to a sed to ditch characters up to and
| including the ^B.
| As I think of it, the first awk could be a sed filter too.

You know, if you're looking to replace the original file with a sorted one,
you could do the whole thing in ex.  Let's say your field separator is a
space:

ex - file << \,,
%s/.* \(.*\)/\1 &/
%!sort
%s/[^ ]* //
wq
,,

David Tamkin  PO Box 7002  Des Plaines IL  60018-7002  dattier at vpnet.chi.il.us
GEnie:D.W.TAMKIN  CIS:73720,1570  MCIMail:426-1818  708 518 6769  312 693 0591

"Parker Lewis Can't Lose" mailing list:
 flamingo-request at esd.sgi.com (relay)  flamingo-request at ddsw1.mcs.com (digest)



More information about the Comp.unix.shell mailing list