bash sort unusual order. Problem with spaces?

后端 未结 2 1893
一生所求
一生所求 2021-01-18 05:17

Lots of time gone in to a bug, which tracks back to sort...

Can someone explain why I get this unsorted result, when the bash docs tell me the delimiter is a transit

相关标签:
2条回答
  • 2021-01-18 06:05

    I think you are seeing locale-based issues. Some (many?) locales affect the way sort works, in that certain chars will be ignored. In this case, it looks like the space between the fields are being ignored when you don't specify the fields to sort. Remove the space and you can see that the row that looks like it's in the wrong place is correct.

    If you run sort with a different locale you'll probably get a different result:

    $ LANG=C sort myfile.txt
    

    My default locale is en_AU.UTF-8 and I see your original sort results. When I set LANG=C, I see the results you are expecting.

    0 讨论(0)
  • 2021-01-18 06:13

    Works right for me:

    $ sort myfile.txt
    10_1000000 44
    10_10000000 19
    10_10000001 20
    10_10000002 19
    10_10000003 17
    10_10000004 16
    10_10000005 16
    10_10000006 16
    10_10000007 17
    10_10000008 16
    
    $ sort --version
    sort (GNU coreutils) 8.5
    

    Perhaps your version requires the -n flag to turn on numerical-sort?

    0 讨论(0)
提交回复
热议问题