如果有尾字段,为什么排序命令的排序方式不同?

问题描述:

考虑排序关键字:一,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