How to sort on exactly one field only

Rob McMahon cudcv at warwick.ac.uk
Thu Oct 25 02:12:10 AEST 1990


In article <quan.656735656 at sol> quan at sol.surv.utas.oz (Stephen Quan) writes:
>ARaman at massey.ac.nz (Anand Venkata Raman) writes:
>
>>I want to sort a file exclusively on field #2.
>>For example,
>>A portion of the file looks like
>>appl1  3  Submitted
>>appl2  4  Submitted
>>appl1  3  Started
>>appl3  5  Submitted
>>appl2  4  Started
>>appl1  3  Finished(0)
>>appl2  4  Finished(7)
>>appl3  5  Started
>>appl3  5  Finished(3)
>
>cat -n file | awk "{print \$3,\$1,\$2,\$4}" | sort | awk "{print \$3,\$1,\$4}"

Close, but there's no need for two awks (which will mess up the formatting if
white space is important), and you were right about the missing -n:

cudcv (5) > cat -n xx | sort -n +2 -3 +0 -1 | colrm 1 8
appl1  3  Submitted
appl1  3  Started
appl1  3  Finished(0)
appl2  4  Submitted
appl2  4  Started
appl2  4  Finished(7)
appl3  5  Submitted
appl3  5  Started
appl3  5  Finished(3)
cudcv (6) > 

(SystemV-ers will use `cut -c8-' instead of `colrm 1 8'.)

Rob
--
UUCP:   ...!mcsun!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv at uk.ac.warwick             INET:   cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England



More information about the Comp.unix.shell mailing list