sort -t: Set the Field Separator
sort -t tells sort which character delimits fields so -k can target a column.
Without -t, sort splits on a non-blank to blank transition. For CSV or colon data you must name the delimiter yourself.
What it does
sort -t C sets C as the single-character field separator used to locate -k keys. With -t, every separator starts a new field, so consecutive separators produce empty fields, unlike the default whitespace mode that collapses runs of blanks.
Common usage
sort -t, -k2,2 data.csv # sort CSV by 2nd column
sort -t: -k3,3n /etc/passwd # numeric sort on UID
sort -t$'\t' -k1,1 data.tsv # tab-separatedOptions
| Flag | What it does |
|---|---|
| -t <char> | Use <char> as the field separator |
| -t $'\t' | Use a literal tab as the separator |
| -k F1,F2 | Field range the separator defines |
| -n / -r | Per-key modifiers attach to -k |
In CI
For tab-separated data, pass -t $'\t' (ANSI-C quoting) rather than a literal tab you cannot see in the script. The default no-t mode treats runs of spaces as one separator; with -t, two spaces make an empty middle field.
Common errors in CI
sort -t " " behaves differently from the default: a literal space separator does not collapse runs, so multiple spaces create empty fields and shift your columns. Real CSV with quoted commas cannot be parsed by -t, since sort has no quoting awareness; use a CSV-aware tool for that.