UNIX排序会忽略空格 [英] UNIX sort ignores whitespaces
本文介绍了UNIX排序会忽略空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
提供文件txt
:
ab
a c
a a
致电sort txt
时,我获得:
a a
ab
a c
换句话说,这不是正确的排序,它会删除/忽略空格!我以为这是sort -i
的行为,但是无论是否带有-i
标志,它都会发生.
In other words, it is not proper sorting, it kind of deletes/ignores the whitespaces! I expected this to be the behavior of sort -i
but it happens with or without the -i
flag.
我想获得正确的"排序:
I would like to obtain "correct" sorting:
a a
a c
ab
我应该怎么做?
推荐答案
解决方案:
export LC_ALL=C
警告:环境指定的语言环境会影响排序顺序.设置LC_ALL = C可获得使用本机字节值的传统排序顺序.
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.
(至少适用于ASCII,不适用于UTF8)
(works for ASCII at least, no idea for UTF8)
这篇关于UNIX排序会忽略空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文