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.

Posted in computing, linux. Tags: , , .

2 Responses to “Linux tip: sort a tab-delimited file”

  1. Pierre Says:

    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

  2. nsaunders Says:

    Or indeed, do it Pierre’s way. Nice tip.

Leave a Reply