Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!aero-c!gumby.dsd.trw.com!ondine.dsd.trw.com!suhre From: suhre@ondine.dsd.trw.com (Maurice E. Suhre) Newsgroups: comp.unix.shell Subject: Re: How to sort on right most column Message-ID: <1991May17.164744.5668@gumby.dsd.TRW.COM> Date: 17 May 91 16:47:44 GMT References: <13320@exodus.Eng.Sun.COM> Sender: news@gumby.dsd.TRW.COM Reply-To: suhre@ondine.dsd.trw.com.UUCP (Maurice E. Suhre) Organization: TRW Space and Defense Lines: 21 In article <13320@exodus.Eng.Sun.COM> rock@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@trwrb.dsd.trw.com