Article View: comp.unix.shell
Article #1532Re: How to sort on exactly one field only
From: Rob Lemley
Date: Wed, 24 Oct 1990 22:22
Date: Wed, 24 Oct 1990 22:22
40 lines
1619 bytes
1619 bytes
In <1094@massey.ac.nz> ARaman@massey.ac.nz (Anand Venkata Raman) writes:
>I want to sort a file exclusively on field #2.
. . .
>I tried using sort +1 -2, but that doesn't seem to deter sort from looking
>at field #3.
Anand, you cannot deter sort from looking at field three. Try this:
cat <<EOF | sort +1 -2 +2r
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)
EOF
The +2r sorts the third field in reverse order.
The man page clearly states that you cannot cause sort to ignore a field
or preserve relative line ordering. From the sort(1) man page
(sys V release 3), under DESCRIPTION:
When there are multiple sort keys, later keys are compared only
after all earlier keys compare equal. Lines that otherwise
compare equal are ordered with all bytes significant.
^^^^^^^^^^^^^^^^^^^^^
and (from WARNINGS):
sort does not guarantee preservation of relative line ordering
on equal keys.
--
-Rob Lemley, System Consultant, Scanning Software, Intergraph, Huntsville, AL
...!uunet!ingr!b15!rob OR b15!rob@INGR.COM
205-730-1546
Technical Details
Message-ID:
<1757@b15.INGR.COM>Path:
arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!ingr!References:
<1094@massey.ac.nz>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!ingr! From: rob@b15.INGR.COM (Rob Lemley) Newsgroups: comp.unix.shell,comp.unix.questions Subject: Re: How to sort on exactly one field only Message-ID: <1757@b15.INGR.COM> Date: 24 Oct 90 22:22:54 GMT References: <1094@massey.ac.nz> Organization: Intergraph Huntsville Lines: 40 th: b15!rob