Linux整行排序没有正确排序
Linux whole-line sort does not sort correctly
我想使用 linux 命令对文件进行整行排序 sort
。
我的档案cat hello
#_
*
#1
当运行与sort hello
#_
*
#1
因为#
在ascciitable中站在*
之前,我的预期结果是
#_
#1
*
有没有人可以解释一下为什么?谢谢。
默认gnu sort不按字节排序,也就是说,不会按照ascii的顺序table.检查这个例子:
kent$ cat f1
a
b
c
A
B
C
kent$ sort f1
a
A
b
B
c
C
如果希望排序按字节排序,可以设置LC_ALL
:
kent$ LC_ALL=C
kent$ sort f1
A
B
C
a
b
c
因此,使用 LC_ALL=C
,您也可以获得预期的输出。
kent$ cat f
#_
*
#1
kent$ sort f
#1
#_
*
更新
我刚刚查看了手册页,它也按字面意思说明了这一点:
* 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.
我想使用 linux 命令对文件进行整行排序 sort
。
我的档案cat hello
#_
*
#1
当运行与sort hello
#_
*
#1
因为#
在ascciitable中站在*
之前,我的预期结果是
#_
#1
*
有没有人可以解释一下为什么?谢谢。
默认gnu sort不按字节排序,也就是说,不会按照ascii的顺序table.检查这个例子:
kent$ cat f1
a
b
c
A
B
C
kent$ sort f1
a
A
b
B
c
C
如果希望排序按字节排序,可以设置LC_ALL
:
kent$ LC_ALL=C
kent$ sort f1
A
B
C
a
b
c
因此,使用 LC_ALL=C
,您也可以获得预期的输出。
kent$ cat f
#_
*
#1
kent$ sort f
#1
#_
*
更新
我刚刚查看了手册页,它也按字面意思说明了这一点:
* 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.