按数字排序按第二列排序,按字母顺序排序

时间:2016-03-28 14:25:16

标签: bash sorting

我有两列,我想用bash对它们进行排序。

我使用了命令:

sort -k2 -n
c 9
c 11
c 11
sh 11
c 13
c 15
txt 47
txt 94
txt 345
txt 628
sh 3673

这是结果,但我需要按照这样排序:

c 9
c 11
c 11
c 13
c 15
sh 11
sh 3673
txt 47
txt 94
txt 345
txt 628

有什么想法吗?

1 个答案:

答案 0 :(得分:11)

第1列的第一个sort,然后是2:

sort -k1,1 -k2,2n file.txt
相关问题