linux "sort -k" - Reverse sort order of a multicolumn file in BASH




1 Answers

Have you tried -r ? From the man page:

-r, --reverse

          reverse the result of comparisons
unix ascending and

I've the following file:

1 2 3
1 4 5
1 6 7
2 3 5
5 2 1

and I want that the file be sorted for the second column but from the largest number (in this case 6) to the smallest. I've tried with

sort +1 -2 file.dat

but it gives me the inversed order.

The results should be:

1 6 7
1 4 5
2 3 5
5 2 1
1 2 3



Related