在最后一个空格之后对grep输出的数值进行排序

时间:2019-05-16 06:43:12

标签: python awk grep

启动grep后,我得到以下输出:

2.txt:;Number of recorded Units: 16
3.txt:;Number of recorded Units: 15
4.txt:;Number of recorded Units: 26
5.txt:;Number of recorded Units: 22
6.txt:;Number of recorded Units: 12
7.txt:;Number of recorded Units: 3
8.txt:;Number of recorded Units: 19
9.txt:;Number of recorded Units: 3
10.txt:;Number of recorded Units: 7
11.txt:;Number of recorded Units: 3
12.txt:;Number of recorded Units: 35

例如,我已经安装了gawk,但是我不知道如何编写它。 我希望这样的输出: 我有gawk,有人可以提供:

7.txt:;Number of recorded Units:    3
9.txt:;Number of recorded Units:    3
11.txt:;Number of recorded Units:   3
10.txt:;Number of recorded Units:   7
6.txt:;Number of recorded Units:   12
3.txt:;Number of recorded Units:   15
2.txt:;Number of recorded Units:   16
1.txt:;Number of recorded Units:   18
8.txt:;Number of recorded Units:   19
5.txt:;Number of recorded Units:   22
4.txt:;Number of recorded Units:   26
12.txt:;Number of recorded Units:  35

(条目的顺序(此处为3)相同的值并不重要)。 还是有其他更适合的工具/程序(例如Python脚本)?

1 个答案:

答案 0 :(得分:2)

尝试一下:

..yourGrep|sort -n -t':' -k3