[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#9808: sort behavior [was: bug#9808: bug report]
From: |
Eric Blake |
Subject: |
bug#9808: sort behavior [was: bug#9808: bug report] |
Date: |
Thu, 20 Oct 2011 07:48:58 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.4 Thunderbird/3.1.15 |
tag 9808 = notabug
thanks
Re-adding the list, so that others may benefit from the solution or
chime in with suggestions.
On 10/20/2011 07:36 AM, mohamad hadi kianersi wrote:
yes,but view these
1.
address@hidden ~]$ printf '10 a\n1 b\n2 c\n' | sort -k1,1 -r -n
10 a
2 c
1 b
but
address@hidden ~]$ printf '10 a\n1 b\n2 c\n' | sort -k1,1r -n
2 c
10 a
1 b
cant sorted with numeric
Did you try 'sort --debug' like I suggested?
$ printf '10 a\n1 b\n2 c\n' | LC_ALL=C sort -k1,1r -n --debug
sort: using simple byte comparison
sort: option `-n' is ignored
2 c
_
___
10 a
__
____
1 b
_
___
Notice - sort is _correctly_ ignoring -n, and --debug even tells you so,
per the rules given by POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html
"The following options shall override the default ordering rules. When
ordering options appear independent of any key field specifications, the
requested field ordering rules shall be applied globally to all sort
keys. When attached to a specific key (see -k), the specified ordering
options shall override all global ordering options for that key." [d, f,
i, n, r]
That is, the moment you use -k with r attached, then the global -n no
longer applies to that -k; to get both r and n behavior on a single key,
you have to attach both options to that -k:
$ printf '10 a\n1 b\n2 c\n' | LC_ALL=C sort -k1,1rn --debug
sort: using simple byte comparison
10 a
__
____
2 c
_
___
1 b
_
___
As such, I'm closing this bug report, now that we know the problem was a
usage error and not a bug in sort.
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org