Take the 2-minute tour ×

This question already has an answer here:

I have a tab-separated file, and I want to sort it by its columns 9, 14, and 16. By this I mean that all rows that agree at column 9 should be sorted by column 14, and among these, those that also agree on column 14 should be sorted by column 16. (All columns should be sorted ascendingly, but the first two should be sorted alphabetically, and the remaining one numerically.)

I've tried various forms of (gnu) sort, but I don't get the desired sort order. The man page has not helped. Can anyone tell me the right incantation for achieving the sort described above?

share|improve this question

marked as duplicate by slm, rush, Anthon, jasonwryan, Gilles Jun 10 '13 at 22:49


1 Answer 1

up vote 3 down vote accepted
sort -t '\t' -k9,9 -k14,14 -k16,16n

(remember you need to specify where sort keys start and where they end, otherwise (as in when you use -k9 instead of -k9,9) they end at the end of the line).

share|improve this answer
