Tomasz
Tomasz

Reputation: 568

symmetric sorting in bash

I have given list of data following:

0.0,0.0,value
1.0,0.0,value
...
40.0,0.0,value
0.0,1.0,value
1.0,1.0,value
...
40.0,1.0,value
...
40.0,120.0,value

and I would like to sort second column in symmetric way, but maintain the order of first column, so the output would look like:

0.0,120.0,value
1.0,120.0,value
...
40.0,120.0,value
0.0,119.0,value
...
40.0,119.0,value
...
40.0,0.0,value

I have no idea which bash command line/script I should use.

Upvotes: 1

Views: 50

Answers (1)

ashish_k
ashish_k

Reputation: 1581

This should work:

sort -t ',' -k2,2nr file_name

Explanation:

-t : field-separator (here it's `,`)
-k, --key=POS1[,POS2]   Where POS1 is the starting field position, and POS2 is the ending field position
-n : numeric-sort
-r : reverse

Upvotes: 2

Related Questions