GNU bug report logs - #5958
Sort-8.4 bug

Previous Next

Package: coreutils;

Reported by: srodri <at> datsi.fi.upm.es

Date: Fri, 16 Apr 2010 12:14:02 UTC

Severity: normal

Merged with 5991

Fixed in version 8.5

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: Santiago Rodriguez <srodri <at> fi.upm.es>
Cc: 5958 <at> debbugs.gnu.org
Subject: bug#5958: Sort-8.4 bug
Date: Fri, 16 Apr 2010 08:12:20 -0600
[Message part 1 (text/plain, inline)]
On 04/16/2010 04:58 AM, Santiago Rodriguez wrote:
> Dear sirs,
> 
> I think I have found a bug in sort coreutils command. When I type
> 
> sort -T /tmp +1 -2 +2rn -3 +0 -1<<EOF
> perra/S perra 2.200000
> perro/PS perra 4.400000
> EOF

Thanks for the report; however, this is not a bug.

The syntax 'sort +1' is obsolete.  You are better off rewriting your
scripts to conform to POSIX:

sort -T /tmp -k2,3 -k3,4rn -k1,2

And in doing so, you've just made it apparent why sort behaved
correctly, but differently than you expected.  Basically, you have
requested that your first sort key be the combination of the second and
third field.  And since 'perra 2.200000' sorts before 'perra 4.400000',
there is no need for sort to fall back on the second and third key
specifications.

You can get the desired results with:

sort -T /tmp -k2,2 -k3,3rn -k1,1

or the obsolete:
sort -T /tmp +1 -1 +2rn -2 +0 -0

Meanwhile, we have a patch brewing (but not in 8.4) that allows sort to
output some debug hints, to actually show which portions of each line
were used in the various comparisons.  I'm hoping we can get that patch
polished soon, because it would have been very helpful in demonstrating
my reply.

> 
> The result is the same. If I make the same executions with sort 5.0 it
> works properly.

Actually, sort 5.0 was buggy in this area.  Sort 8.4 has a number of bug
fixes for bad behavior in sort 5.0.

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 15 years and 35 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.