bash 如何根据字符代码或 ASCII 代码值对文本文件进行排序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5296428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to sort a text file according to character code or ASCII code value?
提问by While Loop
I would like to sort lines of text according to character code or ASCII code value by command line. I tried the following command line but the result is not what I expected.
我想通过命令行根据字符代码或 ASCII 代码值对文本行进行排序。我尝试了以下命令行,但结果不是我所期望的。
# string=" 8888888
>'
> Transportation
> Temp
>temp
>TEMP
> 99
> Temp
> Temporary"
# LC_ALL=C echo "$string" | sort
'
8888888
99
temp
Temp
Temp
TEMP
Temporary
Transportation
To sort according to ASCII code value, the output should look like
要根据 ASCII 码值排序,输出应如下所示
99
Temp
8888888
Temporary
Temp
Transportation
'
TEMP
temp
Does anyone know how to do that?
有谁知道这是怎么做到的吗?
回答by Ignacio Vazquez-Abrams
You've frobbed the wrong program.
你抢错了程序。
echo "$string" | LC_ALL=C sort
Using $LC_COLLATEis also acceptable.
使用$LC_COLLATE也是可以的。

