Sort a tab delimited file based on column sort command bash [duplicate] Sort a tab delimited file based on column sort command bash [duplicate] shell shell

Sort a tab delimited file based on column sort command bash [duplicate]


To sort on the fourth column use just the -k 4,4 selector.

sort -t $'\t' -k 4,4 <filename>

You might also want -V which sorts numbers more naturally. For example, yielding 1 2 10 rather than 1 10 2 (lexicographic order).

sort -t $'\t' -k 4,4 -V <filename>

If you're getting errors about the $'\t' then make sure your shell is bash. Perhaps you're missing #!/bin/bash at the top of your script?


I believe you have an errant $ in your command.

Try:

sort -t\t -nk4