考虑排序键:a、a01 和 a02,如果没有尾随字段,排序结果如下所示:
$ cat test1
a01
a
a02
$ sort test1
a
a01
a02
$
但是如果有拖尾场,事情就会变得奇怪:
$ cat test2
a01 7
a 12
a02 42
$ sort test2
a01 7
a02 42
a 12
$
为什么键“a”在排序结果中会从上往下掉落?
我的排序版本是“sort (GNU coreutils) 5.97”。
最佳答案
我的 sort
版本的手册页说:
*** WARNING *** The locale specified by the environment affects sort order.
Set LC_ALL=C to get the traditional sort order that uses native byte values.
事实上,如果我设置 LC_ALL=C
并在您的第二个示例中运行 sort
,我会得到:
$ LC_ALL=C sort < tosort
a 12
a01 7
a02 42
您的默认定位可能不是 C
。
关于linux - 如果有尾随字段,为什么 sort 命令排序不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10309033/