2012-04-25 37 views
0

考慮排序關鍵字:一,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」。

回答

1

對我的版本的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

相關問題