LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sort command (https://www.linuxquestions.org/questions/linux-newbie-8/sort-command-841250/)

coffee arabia 10-29-2010 04:46 PM

sort command
 
Hi,

I want to sort a file contains

9 1
9 2
10 1
10 2

to the order of

10 1
9 1
10 2
9 2

That is, the 2nd column is in incremental order, but for lines with the same 2nd column number, they are sorted in a reversed order.

I tried
Sort –k2 –k1 –n –r
But got everything in reversed order

10 2
9 2
10 1
9 1

Is there any simple way that works? Right now, I have to write a script to process this.

Thanks,

Tinkster 10-29-2010 04:57 PM

Sure is

sort -k2,2n -k1,1nr

colucix 10-29-2010 05:01 PM

Code:

sort -k2n -k1nr file
Edit: ops... too late! ;)

coffee arabia 10-29-2010 05:10 PM

Great, thanks for both of you!!!


All times are GMT -5. The time now is 08:07 PM.