linux - 如果有尾随字段,为什么 sort 命令排序不同?

标签 linux shell sorting

考虑排序键: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/

相关文章:

linux - Makefile install 复制可执行文件到 usr/local/bin Linux

linux - echo $HTTP 作为纯文本

python - 在 Paramiko 中执行多个命令,以便命令受其前任的影响

python - Django:获得顶级标签?

java - 哪种算法在 Stream 接口(interface)中使用 sorted 方法

algorithm - 节省内存的归并排序

c++ - C++中引用变量的地址

c - ino_t 的占位符

git 编辑提交范围内的作者姓名,脚本

bash - 在 shell 别名中设置环境变量