Format text into aligned columns
Take tab- or whitespace-separated text and produce aligned columns — for human-readable tables, `mount` / `df` output reformatting, and CSV pretty-printing.
How to format text into aligned columns in each shell
Bashunix
column -t -s , input.csv`-t` enable column auto-detect; `-s ,` use comma as separator. GNU `column` (`util-linux`) handles `-t -s` correctly. The default separator is whitespace; use `-s` for CSV / TSV.
Zshunix
column -t -s , input.csvFishunix
column -t -s , input.csvPowerShellwindows
Import-Csv input.csv | Format-Table -AutoSize`Format-Table -AutoSize` measures columns and formats. Format string control: `Format-Table @{Label="Path"; Expression={$_.Path}; Width=30}, Size`. For non-object input: `Get-Content input.txt | ConvertFrom-Csv -Delimiter "," | Format-Table -AutoSize`.
cmd.exewindows
powershell -NoProfile -Command "Import-Csv input.csv | Format-Table -AutoSize"cmd has no columnize tool. `for /f` can read lines but has no width-padding output. Always shell out.
Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.
Gotchas & notes
- **BSD vs GNU `column` divergence**: GNU `column` (from `util-linux`, Linux default) supports `-t` (table mode) combined with `-s SEP` (separator) correctly: `column -t -s ,` produces CSV-aligned columns. BSD `column` (macOS native) historically IGNORES `-s` when `-t` is set (the two flags are mutually exclusive in old BSD `column`). On macOS, `column -t -s , input.csv` produces SPACE-aligned output (treating the comma as part of the value). The workaround: pipe through `tr "," "\t"` first (`tr "," "\t" < input.csv | column -t`) so column sees real tabs; OR `brew install util-linux` and use `/usr/local/opt/util-linux/bin/column` (GNU variant). macOS 12.3+ Monterey shipped an updated BSD column that DOES support `-s`, narrowing the gap — check `column --version`.
- **Portable fallback via `printf`**: when you can\'t rely on `column` behavior, use `printf` with field-width specifiers: `awk -F, \'{printf "%-20s %-20s %-10s\n", $1, $2, $3}\' input.csv` — `%-20s` is "left-align in 20-char field"; `%20s` (no minus) is right-align. Works on every Unix awk + bash printf. The downside: hardcoded widths that don\'t adapt to data. For "compute the max width then print" pre-scan logic: `awk -F, \'NR==FNR{for(i=1;i<=NF;i++) m[i]=length($i)>m[i]?length($i):m[i]; next} {for(i=1;i<=NF;i++) printf "%-*s ", m[i], $i; print ""}\' input.csv input.csv`.
- **pwsh `Format-Table` is for HUMAN display only** — its output is unparseable. Never pipe `Format-Table` into another cmdlet — you\'ll lose all object properties. Use `Format-Table` only at the END of a pipeline for terminal display. For data processing in pwsh: keep working with objects, use `Select-Object` for column selection, `Sort-Object` for ordering. `Format-Table` strips the object structure and returns formatting-instruction objects that no other cmdlet understands. This is the most-common pwsh footgun for newcomers.
- **Beyond `column`**: for fancier tabular output `pretty-table` (`pip install ptable`), `csvlook` (`pip install csvkit`), and `mlr --csv --opprint` (`brew install miller`) handle quoting, multi-line cells, and Unicode width better than column. `miller` is the swiss-army knife for CSV/TSV/JSON tabular ops — `mlr --csv cat input.csv` for pretty-print; `mlr --csv stats1 -a mean,sum -f col1,col2 input.csv` for ad-hoc aggregations. For "Markdown table from CSV": `mlr --icsv --omd cat input.csv` or `csvkit` `csvtomd`. For wide CSVs that don\'t fit terminal width, `mlr --csv --barred` draws a box around each row for readability.
Related commands
Related tasks
- Normalize whitespace in text— Collapse multiple spaces / tabs into single spaces and strip line-leading / trailing whitespace — for diff-friendly text, CSV cleanup, and config-file canonicalization.
- Sort a file by a specific column— Sort lines of a file by the value in a chosen column (numeric or alphabetic).
- Minify a JSON file— Strip whitespace and indentation from a JSON file to produce the smallest valid output.