bug-coreutils
[Top][All Lists]
Advanced

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

Re: sort's -u is Failing to Check all -k fields for Uniqueness.


From: Eric Blake
Subject: Re: sort's -u is Failing to Check all -k fields for Uniqueness.
Date: Sat, 19 Aug 2006 14:08:37 +0000

> This seems wrong.
> 
>     $ echo 1/3,1/2,1/1,2/1 | tr , \\012 | sort -nu -t / -k 1,2
>     1/3
>     2/1
>     $
> 
> -u should only filter out lines that compare equal on *all* key fields.
> I've opened an Ubuntu bug at
> https://launchpad.net/distros/ubuntu/+source/coreutils/+bug/56891 which
> has more detail and examples.  I was hoping someone here could either
> confirm it's a bug or point out my misunderstanding.

According to POSIX, -n will "Restrict the sort key to an initial numeric 
string",
and -t "can be included in a sort key".  You specified only one sort key,
namely the string that extends from field 1 (the first digit) through field 2
(the second digit), including the delimiter /, which is non-numeric, so
sort is properly sorting numerically on the initial numeric string of your
specified key (and hence, you only get two outputs).  Try instead specifying
a primary and secondary key:

$ echo 1/3,1/2,1/1,2/1 | tr , \\012 | sort -u -t / -k1n,1 -k2n,2
1/1
1/2
1/3
2/1
$

-- 
Eric Blake





reply via email to

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