GNU bug report logs - #23673
wrong sorting order

Previous Next

Package: coreutils;

Reported by: alainm <alain.miniussi <at> oca.eu>

Date: Wed, 1 Jun 2016 15:33:01 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 23673 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: alainm <alain.miniussi <at> oca.eu>, 23673 <at> debbugs.gnu.org
Subject: Re: bug#23673: wrong sorting order
Date: Wed, 1 Jun 2016 11:44:47 -0400
tag 23673 notabug
close 23673
stop

Hello Alain,

On 06/01/2016 09:16 AM, alainm wrote:
> I need to perform a sort based on the first 3 indexes of a line (sort -k 1,3 -n truc.lst):
>
> The 0 coordinates are not placed before the 2 coordinates, it looks like the spaces are ignore:
[...]
>
> [alainm <at> tagir 1src]$  sort  -k 1,3 -n truc.lst

To sort multiple numeric fields, use separate "-k" parameters, like so:

    sort -k1,1 -k2,2 -k3,3 -n truc.list

If in the future you wish to combine different ordering (e.g. numeric and alphanumeric, or some fields in reverse order),
consider specifying the order in each key instead of globally:

    sort -k1n,1 -k2nr,2 -k3n,3 truc.list

> [alainm <at> tagir 1src]$ sort --version
> sort (GNU coreutils) 8.4

If you upgrade to coreutils version 8.6 or later, sort will accept '--debug' option, which will help you troubleshoot such cases:

    $ sort --debug -k 1,3 -n truc.lst
    sort: using ‘en_US.UTF-8’ sorting rules
    sort: key 1 is numeric and spans multiple fields
    [...]


I'm marking this bug as done, but discussion can continue by replying to this thread.

regards,
 - assaf






This bug report was last modified 6 years and 213 days ago.

Previous Next


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