Article View: comp.unix.shell
Article #1617Re: How to sort on exactly one field only
From: Rob McMahon
Date: Wed, 24 Oct 1990 16:12
Date: Wed, 24 Oct 1990 16:12
40 lines
1641 bytes
1641 bytes
In article <quan.656735656@sol> quan@sol.surv.utas.oz (Stephen Quan) writes:
>ARaman@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@uk.ac.warwick INET: cudcv@warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England
Technical Details
Message-ID:
<1990Oct24.161210.15831@warwick.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!warwick!cudcvReferences:
<1094@massey.ac.nz> <quan.656735656@sol>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.unix.shell Subject: Re: How to sort on exactly one field only Message-ID: <1990Oct24.161210.15831@warwick.ac.uk> Date: 24 Oct 90 16:12:10 GMT References: <1094@massey.ac.nz> <quan.656735656@sol> Sender: news@warwick.ac.uk (Network news) Organization: Computing Services, Warwick University, UK Lines: 40