How to sort on right most column
Maurice E. Suhre
suhre at ondine.dsd.trw.com
Sat May 18 02:47:44 AEST 1991
In article <13320 at exodus.Eng.Sun.COM> rock at warp.Eng.Sun.COM (Bill Petro) writes:
>
>How could I do this using either the sort command, or perl or awk?
>
>I have the following data in this format - I want to sort it on the
>right most column.
[Most of data file deleted for brevity]
> FOO BAR CITIBANK N. A. ANDOVER 4.00
> FOO BAR CITIBANK NORTH AMERICA LONG ISLAND CITY 26.00
>
I haven't seen an awk solution yet, so here's one. The strategy is
to generate a line which has the last field duplicated in front and
uses a different field separator. I selected the "plus" sign. There
needs to be some character which is not found in the data file.
#! /bin/sh
#
awk '{print $NF "+" $0}' | sort -n -t+ +0 -1 ,t1 | awk -F+ '{ print $2}'
--
Maurice Suhre
suhre at trwrb.dsd.trw.com
More information about the Comp.unix.shell
mailing list