我想按名称和计数对文件进行排序。如何根据计数进行降序排序,并在遇到平局时按升序对名称进行排序?
例如:
a 31
b 82
d 21
l 31
o 21
至
b 82
a 31
l 31
d 21
o 21
我尝试使用sort -k 2r -n -t $'\t'输出-o输出
但它不起作用。
有人可以帮我解决这个问题吗?
最佳答案
您可以使用:
sort -t $'\t' -k2rn -k1 file
b 82
a 31
l 31
d 21
o 21
排序
选项:
-t $'\t' # use tab as field delimiter
-k2rn # first sort on reverse numeric order on field2
-k1 # then sort on natural (alphabetic) order of field1
关于bash - 如何处理 bash 的平局条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39420589/