Linux Command Reference ยท Text Processing
Linux column command
Reference for the Linux column command: align text into a table with -t, set the separator with -s, fill columns, and the differences between versions.
column arranges text into columns. Its best-known use is column -t, which reads whitespace-separated fields and pads them into an aligned table. Without -t it fills a list of items across the terminal width, like ls does.
column comes from the util-linux package on most distributions (older systems shipped a BSD version in bsdmainutils), and it may be missing from minimal images, including the one that runs this site's examples. The examples below are therefore read-only; the equivalent printf and awk forms that do run are shown after them.
column [OPTION]... [FILE]...
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
column [-t] [-s SEPS] [-o OUTSEP] [-c WIDTH] [-x] [-n] [-N NAMES] [FILE]...
# Read-only examples printf 'a,bb,ccc\n1,22,333\n' | column -t -s, ls | column -c 60
| Option | Description |
|---|---|
-t |
Table mode: create a table from the input fields, one row per input line. |
-s CHARS |
Characters that separate input fields (default: whitespace). In table mode each character is a delimiter. |
-o STRING |
Output separator between columns in table mode (default two spaces). |
-c N |
Output width in characters; default is the terminal width. |
-x |
Fill rows before columns (default is columns before rows). |
-N NAMES, -R |
util-linux: set column names and right-align columns. |
-n |
util-linux: do not merge adjacent delimiters. |
-J |
util-linux: print the table as JSON (needs -N). |
Returns: 0 on success, non-zero on error.
Usage notes
- Empty fields are merged in table mode when the separator is a whitespace character, because adjacent delimiters count as one. With
-s,, two commas in a row still collapse into one on older versions: use-non util-linux, or fill empty cells with a placeholder such as-. - The last column is not padded, so no trailing spaces appear.
- Differences between versions: the BSD
columnlacks-N,-Jand-n. The util-linux one (2.23+) has them. Checkcolumn --version, or fall back toawkorprintffor portable scripts. - Wide characters and escape codes (colors) break alignment, because
columncounts characters, not display width. Strip colors withsedbefore columnizing. - Not CSV-aware: quoted fields containing separators are split anyway. Use a real CSV tool for those.
- Typical use: align command output for humans, as in
mount | column -t. Do not feed aligned output back into scripts; use a proper delimiter instead. - Header row:
columnhas no concept of a header, so combine it withsortcarefully (sort the body, then add the header).
Related
fmt,paste,awk,printf- Lessons: printf and date, Text processing recipes