coreutils
[Top][All Lists]
Advanced

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

Re: sort:An unexpected result is displayed in the sort result.


From: Pádraig Brady
Subject: Re: sort:An unexpected result is displayed in the sort result.
Date: Fri, 5 Nov 2021 15:21:21 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0

On 05/11/2021 09:31, Yang Yanchao wrote:
Dear Coreutils Maintainers,

When I sort the use cases using "sort":
[root@localhost test]# cat test
1.2.v1.6
1.0.v3.5
1.10.v2.4
[root@localhost test]# sort -n -t'.' -k3,3 -k4,4 test
1.10.v2.4
1.0.v3.5
1.2.v1.6

The order I expected should be like this.
1.2.v1.6
1.10.v2.4
1.0.v3.5

It looks like the third column is alphabetic, and I added the -n option, which 
was ignored, but I used -k to specify the third column as the first 
priority.This means that -k has a lower priority than -n? Does this fit the 
intended design?

If you use the --debug option it shows -k3,3 is not matching
(due to not being numeric):

  $ printf '%s\n' 1.2.v1.6 | sort -n -t'.' -k3,3 -k4,4 --debug
  sort: text ordering performed using ‘en_IE.UTF-8’ sorting rules
  1.2.v1.6
      ^ no match for key
         _

You probably want to restrict the numeric comparison to field 4 (with -k4,4n).
You probably also want to use --version-sort on field 3
rather than lexicographically (with -k3,3V), so that v10 sorts after v9:

$ printf '%s\n' 1.2.v10.6 1.0.v3.5 1.10.v2.4 |
  sort -t'.' -k3,3V -k4,4n --debug
1.10.v2.4
     __
        _
1.0.v3.5
    __
       _
1.2.v10.6
    ___
        _

cheers,
Pádraig



reply via email to

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