emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#9995: closed (problem about sort -u -k)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#9995: closed (problem about sort -u -k)
Date: Tue, 08 Nov 2011 18:55:04 +0000

Your message dated Tue, 08 Nov 2011 11:54:17 -0700
with message-id <address@hidden>
and subject line Re: bug#9995: problem about sort -u -k
has caused the debbugs.gnu.org bug report #9995,
regarding problem about sort -u -k
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
9995: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9995
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: problem about sort -u -k Date: Tue, 8 Nov 2011 22:49:12 +0800
when i use sort command with -k and -n together, i got the wrong result:
22:41:21#tp#~> LC_ALL=C
22:41:39#tp#~> /usr/local/bin/sort -u -k1,3 a
1 a q
1 a w
3 a w
22:41:48#tp#~> /usr/local/bin/sort -u -k3 a
1 a q
1 a w
22:41:49#tp#~> cat a
1 a q
1 a w
3 a w
22:41:52#tp#~> /usr/local/bin/sort --version
sort (GNU coreutils) 8.14
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.
22:41:57#tp#~>
why is that?
i read http://www.gnu.org/s/coreutils/manual/html_node/sort-invocation.html,
but got nothing about this.
any help is appreciate.
-- 
contact me:
MSN: address@hidden
GTALK: address@hidden



--- End Message ---
--- Begin Message --- Subject: Re: bug#9995: problem about sort -u -k Date: Tue, 08 Nov 2011 11:54:17 -0700 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 9995 notabug
thanks

On 11/08/2011 07:49 AM, 夏凯 wrote:
when i use sort command with -k and -n together, i got the wrong result:

Thanks for the report; however, this is most likely not a bug in sort, but in your usage patterns. Your sentence mentioned -k and -n together, but your example and subject line mentioned -u and -k together; so I'll assume that you got surprised by -u, not -n.

22:41:21#tp#~>  LC_ALL=C

Unless you also did 'export LC_ALL' at some point, this does not guarantee that child processes will see this setting in their environment.

22:41:39#tp#~>  /usr/local/bin/sort -u -k1,3 a
1 a q
1 a w
3 a w
22:41:48#tp#~>  /usr/local/bin/sort -u -k3 a
1 a q
1 a w
22:41:49#tp#~>  cat a
1 a q
1 a w
3 a w
22:41:52#tp#~>  /usr/local/bin/sort --version
sort (GNU coreutils) 8.14

That's new enough that you can use the --debug option to see what was really going on:

$ LC_ALL=C ../coreutils/src/sort --debug -u -k1,3 a
sort: using simple byte comparison
1 a q
_____
1 a w
_____
3 a w
_____

Here, you compared all three lines, which were all distinct.

$ LC_ALL=C ../coreutils/src/sort --debug -u -k3 a
sort: using simple byte comparison
1 a q
   __
1 a w
   __

Here, you told sort to only look at a key of field three onwards, and to uniquify the results (that is, don't display multiple lines if they had the same sort key). Since two lines both have the string " w" as the -k3 key, sort -u picked one of those lines (namely "3 a w") to be discarded on output. This behavior matches POSIX rules.

Since you didn't tell us what output you were hoping to get, I can't tell you the proper command line that would match your expected output. Feel free to reply, even while this bug is closed, if you need more help in getting the output you want. Also, if you can prove that sort is doing something wrong, then feel free to reopen this bug with more evidence of why it is a bug in sort, including --debug output to back up your claim (but be aware that more than 90% of "bug" reports against sort have been debunked as user error rather than an actual bug in sort).

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]