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