Text processing
column
Format input into aligned columns or a table; turns CSV and whitespace data into readable output.
column [OPTION...] [FILE...]
column has two modes. With -t it builds a table: it splits each line into fields
(on whitespace, or on the characters given with -s) and pads every field so the columns line
up. Without -t it fills a list of short items into as many columns as fit the screen
width, like ls does.
column -t -s, is the fastest way to read a CSV in the terminal. The Linux version (from
util-linux, in Debian's bsdextrautils package) adds much more: custom output separators,
right-aligned columns, header names, hiding columns and even JSON output. It is not a CSV
parser, though: it does not understand quoted fields with commas inside.
Examples
Read a CSV as an aligned table
column -t -s , data/users.csv | head -n 5
id name email dept joined 1 Alice Moreau alice@example.com engineering 2021-04-12 2 Bob Okafor bob@example.com sales 2019-11-03 3 Chen Wei chen@example.com engineering 2023-01-20 4 Dana Kowalski dana@example.com support 2022-07-08
-t makes a table and -s , splits fields on commas. Each column is padded to its widest
value, so the names and emails line up.
Align whitespace-separated data
column -t data/hosts.txt
web01 10.0.0.11 web02 10.0.0.12 db01 10.0.0.21 cache01 10.0.0.31
Without -s, fields are split on runs of spaces and tabs, so ragged two-column data gets a straight second column.
Tidy up a command's output
printf '%s %s %s\n' NAME SIZE TYPE app.py 17 python helpers.py 3 python main.c 6 c | column -t
NAME SIZE TYPE app.py 17 python helpers.py 3 python main.c 6 c
Any command that prints space-separated fields can be piped through column -t for a neat table.
Draw visible column separators
column -t -s , -o ' | ' data/sales.csv | head -n 4
date | region | product | units | price 2026-03-01 | north | widget | 12 | 4.50 2026-03-01 | south | gadget | 3 | 19.99 2026-03-02 | east | widget | 7 | 4.50
-o ' | ' sets what goes between output columns (two spaces by default), giving a Markdown-like table.
Right-align numeric columns
column -t -s $'\t' -R 2,3 data/inventory.tsv
name qty price widget 12 4.50 gadget 3 19.99 gizmo 5 12.00
-s $'\t' splits on tabs (bash turns $'\t' into a real tab) and -R 2,3 right-aligns
the quantity and price columns so the digits line up.
Name and hide columns
tail -n +2 data/users.csv | column -t -s , -N id,name,email,dept,joined -H email,joined | head -n 4
id name dept 1 Alice Moreau engineering 2 Bob Okafor sales 3 Chen Wei engineering
-N names the columns and prints the names as a header line; -H then hides columns by
name. The file's own header is skipped with tail -n +2, otherwise it would appear twice.
Convert a table to JSON
tail -n +2 data/users.csv | head -n 2 | column -J -s , -n users -N id,name,email,dept,joined
{
"users": [
{
"id": "1",
"name": "Alice Moreau",
"email": "alice@example.com",
"dept": "engineering",
"joined": "2021-04-12"
},{
"id": "2",
"name": "Bob Okafor",
"email": "bob@example.com",
"dept": "sales",
"joined": "2019-11-03"
}
]
} -J writes JSON: an object whose key is the table name from -n, holding one object per
row keyed by the column names from -N. All values are strings.
Fill a list into columns
seq 1 12 | column -c 40
1 4 7 10 2 5 8 11 3 6 9 12
Without -t, items are arranged in columns down the page, as many as fit into the width
given by -c (the terminal width by default). The gaps are tab characters.
Fill rows first
seq 1 12 | column -x -c 40
1 2 3 4 5 6 7 8 9 10 11 12
-x fills across each row before starting the next, so the numbers read left to right.
Empty fields are kept
printf 'host,port,user\nweb01,,admin\ndb01,5432,\n' | column -t -s ,
host port user web01 admin db01 5432
The missing port of web01 and the missing user of db01 stay as blank cells, so the
columns don't shift. The BSD/macOS column merges adjacent separators instead.
Common pitfalls
column -t -s,is not a CSV parser: a quoted field such as"Smith, Jane"is split at its comma. Use a real CSV tool (python's csv module,mlr,csvlook) for such files.BSD/macOS
columntreats several adjacent separators as one, so empty CSV fields shift the following values one column left. util-linuxcolumnon Linux keeps empty fields.columnreads all input before printing anything, because it needs every row to compute widths. It is useless withtail -fand slow on huge files.
GNU vs BSD and macOS
The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).
The Linux (util-linux)
columnoptions-o,-R,-N,-H,-J,-n,-Wand long options are not available in the BSD/macOS version, which has essentially-t,-s,-cand-x.
Options worth knowing
A selection, described in our own words. For the full list, see column(1) or column --help.
| Option | What it does |
|---|---|
-t, --table | Build a table: split lines into fields and align them. |
-s, --separator CHARS | Characters that separate input fields in table mode (whitespace by default). |
-o, --output-separator STRING | String placed between output columns (two spaces by default). |
-R, --table-right COLUMNS | Right-align these columns (numbers or names). |
-N, --table-columns NAMES | Comma-separated names for the columns. |
-H, --table-hide COLUMNS | Do not print these columns. |
-O, --table-order COLUMNS | Print columns in this order. |
-J, --json | Output JSON; needs column names from -N. |
-n, --table-name NAME | Name of the table, used as the JSON key. |
-W, --table-wrap COLUMNS | Allow these columns to wrap their text. |
-c, --output-width WIDTH | Output width in characters for fill mode. |
-x, --fillrows | Fill rows before columns. |
-L, --keep-empty-lines | Keep empty input lines instead of skipping them. |
Related
cutPrint selected fields, characters or bytes from each line, such as columns of a CSV or TSV file.pasteMerge lines of files side by side, or join all lines of one file into a single line.expandConvert tabs to spaces, keeping the columns where they were; unexpand does the reverse.sortSort lines of text alphabetically, numerically, by version or by chosen fields; also merge and de-duplicate.