Sunday, November 16, 2008

Unix sort on multiple columns

=============== THIS IS NOT QUITE RIGHT! LOOK AT UPDATED BLOG POST IN JANUARY 2010 ===============

To sort on multiple columns using the unix sort command, use the -k option multiple times.

IE, to sort first on column 2, then on column 1, use:

sort -k 2 -k 1 inFile > outFile

To sort the columns in numerical order (instead of string order), put an "n" after the column numbers. ie

sort -k 2n -k 1n inFile > outFile

No comments: