Linux tip: sort a tab-delimited file

The Linux command “sort” is both powerful and confusing. The manpage tells us that the “-t” switch can be used to set the field delimiter.

If you’ve tried various combinations of “-t” and “\t” to tell sort that your file is tab-delimited without success, try this (bash shell):

TAB=`echo -e "\t"`
sort -t"$TAB" myfile

with “-kN” as appropriate, where N is the column on which to sort.

Long-winded discussion with much incorrect syntax in this forum; or get straight to the point in this mail archive.

3 thoughts on “Linux tip: sort a tab-delimited file

  1. Pierre

    Neil,
    when your typing on your keyboard, press Ctrl-V then press the tab key: you’ll get the tab character without calling the linux completion process.

    Pierre

Comments are closed.