Reverse sort order of a multicolumn file in BASH Reverse sort order of a multicolumn file in BASH bash bash

Reverse sort order of a multicolumn file in BASH


sort -nrk 2,2

does the trick.

n for numeric sorting, r for reverse order and k 2,2 for the second column.


Have you tried -r ? From the man page:

-r, --reverse

          reverse the result of comparisons


As mention most version of sort have the -r option if yours doesn't try tac:

$ sort -nk 2,2 file.dat | tac 1 6 71 4 52 3 55 2 11 2 3$ sort -nrk 2,2 file.dat 1 6 71 4 52 3 55 2 11 2 3

tac - concatenate and print files in reverse