This is as documented (in the info file):

     The commands `sort -u' and `sort | uniq' are equivalent, but this
     equivalence does not extend to arbitrary `sort' options.  For
     example, `sort -n -u' inspects only the value of the initial
     numeric string when checking for uniqueness, whereas `sort -n |
     uniq' inspects the entire line.  *Note uniq invocation::.

I'm going to close this, I'm afraid; while it's a little non-obvious,
it's a useful facility and changing it would almost certainly cause
breakage. (Appending uniq is easy if that's what you need; appending
uniq with the right options to consider only certain fields if that's
what you need is more fiddly.)

POSIX
(http://www.opengroup.org/onlinepubs/009695399/utilities/sort.html)
seems to support this interpretation:

-u
    Unique: suppress all but one in each set of lines having equal keys. If 
used with the -c option, check that there are no lines with duplicate keys, in 
addition to checking that the input file is sorted.
-n
    Restrict the sort key to an initial numeric string, consisting of optional 
<blank>s, optional minus sign, and zero or more digits with an optional radix 
character and thousands separators (as defined in the current locale), which 
shall be sorted by arithmetic value. An empty digit string shall be treated as 
zero. Leading zeros and signs on zeros shall not affect ordering.

... that is, by restricting the sort key, -n restricts the range of data
that -u is permitted to consider for uniqueness.

** Changed in: coreutils (Ubuntu)
       Status: New => Won't Fix

-- 
sort -nu removes inequivalent lines
https://bugs.launchpad.net/bugs/179131
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to