Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash sort-n不起作用_Bash_Sorting_Alphabetical - Fatal编程技术网

Bash sort-n不起作用

Bash sort-n不起作用,bash,sorting,alphabetical,Bash,Sorting,Alphabetical,我有一个文件,我想按字母顺序排序: cat file peptide9 peptide89 peptide99 peptide79 peptide4 peptide58 peptide990 当我使用 cat file | sort -n 结果是: peptide4 peptide58 peptide79 peptide89 peptide9 peptide99 peptide990 我尝试了不同的排序选项,但结果总是一样的 我想要的输出是 peptide4 peptide9 peptid

我有一个文件,我想按字母顺序排序:

cat file
peptide9
peptide89
peptide99
peptide79
peptide4
peptide58
peptide990
当我使用

cat file | sort -n
结果是:

peptide4
peptide58
peptide79
peptide89
peptide9
peptide99
peptide990
我尝试了不同的排序选项,但结果总是一样的
我想要的输出是

peptide4
peptide9
peptide58
peptide79
peptide89
peptide99
peptide990
您可以使用
--版本排序(
-V
):

另一种选择是,“使用“e”作为分隔符,将3列作为数字排序”:


按数字排序,键从第1个字符的第8个字符开始 字段:

使用该键进行排序,将其视为数字,而不是其他字段 (如果有其他字段,则很有用):


info sort
了解更多详细信息。

请注意,该版本不适用于负数
$> sort --version-sort t
peptide4
peptide9
peptide58
peptide79
peptide89
peptide99
peptide990
$> sort -te -k3 -n t
peptide4
peptide9
peptide58
peptide79
peptide89
peptide99
peptide990
sort -n -k1.8 file
sort -k1.8n file