Thursday, 12 June 2014

Sort

A key specification like -k2 means to take all the fields from 2 to the end of the line into account. The first comparison in sort -k2 -k1 is enough to discriminate these two lines, and the second sort key -k1 is not invoked.

To sort by a single column, use -k2,2 as the key specification. This means to use the fields from #2 to #2, i.e. only the second field.

sort -k2 -k3 <txt> is redundant: it's equivalent to sort -k2 <txt>.  Run sort -k2,2 -k1,1 <txt>.

Cited from http://unix.stackexchange.com/questions/52762/trying-to-sort-on-two-fields-second-then-first

#######################################
Sort Files Like A Master With The Linux Sort Command (Bash)

#######################################
sort manual



No comments:

Post a Comment