bash short by two columns

烂漫一生 提交于 2019-12-13 07:57:07

问题


I've this dataset:

12363 111111
12363 222222
12363 3456
12364 2895
12364 257363
12364 246291
12364 243701
12364 243699

I would like to sort this by first column, numerical value, reverse and by second column, numerical value, reverse. Result would be:

12364 257363
12364 246291
12364 243701
12364 243699
12364 2895
12363 222222
12363 111111
12363 3456

I tried,

sort -rn
sort -rnk1,2
sort -rg
sort -rgk1,2

But somehow all of these gives back for the second column a wrong order (not numerical, but values):

12364 2895
12364 257363
12364 246291
12364 243701
12364 243699
12363 3456
12363 222222
12363 111111

Do you have any idea how to fix this?

Thanks!!


回答1:


What about this?

$ sort -rn -k1 -k2 file
12364 257363
12364 246291
12364 243701
12364 243699
12364 2895
12363 222222
12363 111111
12363 3456

Note that -k1 -k2 is not the same as -k1,2.



来源:https://stackoverflow.com/questions/24033692/bash-short-by-two-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!