# column — Format Input into Columns and Tables

> Practical guide to column — columnate lists, build aligned tables from delimited data and format command output for better readability in the terminal.

Source: https://www.jpkc.com/db/en/cheatsheets/files-text/column/

<!-- PROSE:intro -->
column formats input into clean, aligned columns or tables – ideal for making messy command output or delimited data readable in the terminal. In its simplest form it spreads a list across several columns that fill the terminal width; with `-t` it detects the number of columns automatically and aligns a proper table. With `-s` you set the input delimiter, with `-o` the output delimiter, and with `-N`, `-H`, `-O` or `-R` you name, hide, reorder and align individual columns. The modern util-linux version can even emit JSON. Note that `column` varies between distributions and versions – the options shown here assume a recent util-linux.
<!-- PROSE:intro:end -->

## Basic Usage

`column <file>` — Fill columns before rows. Formats input into multiple columns to fill the terminal width.

```bash
column /etc/shells
```

`<command> | column` — Columnate command output to fill the terminal width.

```bash
echo -e 'one\ntwo\nthree\nfour\nfive\nsix' | column
```

`column -x <file>` — Fill rows before columns (left to right, then next row).

```bash
ls /usr/bin | column -x
```

`column -c <width> <file>` — Set output width in characters instead of using terminal width.

```bash
column -c 40 names.txt
```

## Table Mode

`column -t <file>` — Create a table. Determine the number of columns and align them.

```bash
column -t /etc/fstab
```

`column -t -s '<sep>' <file>` — Create a table using a custom input delimiter.

```bash
column -t -s ',' data.csv
```

`column -t -s ':' <file>` — Create a table from colon-separated data.

```bash
column -t -s ':' /etc/passwd
```

`column -t -s $'\t' <file>` — Create a table from tab-separated data.

```bash
column -t -s $'\t' data.tsv
```

`column -t -o '<sep>' <file>` — Set the output column separator (default: two spaces).

```bash
column -t -s ',' -o ' | ' data.csv
```

## Column Selection & Naming

`column -t -N <names> <file>` — Set column names as comma-separated list. Adds a header row.

```bash
column -t -N 'Name,Age,City' -s ',' data.csv
```

`column -t -H <columns> <file>` — Hide specified columns from output (by name or 0-based index).

```bash
column -t -s ':' -N 'User,Pass,UID,GID,Info,Home,Shell' -H Pass /etc/passwd
```

`column -t -O <columns> <file>` — Reorder columns in the specified order.

```bash
column -t -s ',' -O 'City,Name,Age' data.csv
```

`column -t -R <columns> <file>` — Right-align specified columns (by name or 0-based index).

```bash
column -t -s ',' -R 'Price,Amount' sales.csv
```

## Advanced Table Options

`column -t -l <count> <file>` — Limit the number of columns in table mode.

```bash
column -t -l 3 data.txt
```

`column -t -e <file>` — Do not ignore empty lines in table mode.

```bash
column -t -e data.txt
```

`column -t -n <file>` — Set the table name (only takes effect with JSON output -J; no visible effect in plain text mode).

```bash
column -t -n -N 'PID,User,Command' -s ',' procs.csv
```

`column -t -W <columns> <file>` — Wrap text in specified columns if it exceeds terminal width.

```bash
column -t -s ',' -W 'Description' items.csv
```

## JSON Output

`column -t -J <file>` — Output table as JSON array of objects (requires -N or header row).

```bash
column -t -s ',' -J -N 'Name,Age,City' data.csv
```

`column -t -J -n <name> <file>` — Set the JSON array name in output.

```bash
column -t -s ',' -J -n 'users' -N 'Name,Email' users.csv
```

## Pipelines

`<command> | column -t` — Align whitespace-separated command output into a clean table.

```bash
mount | column -t
```

`<command> | column -t -s '<sep>'` — Create aligned table from delimited command output.

```bash
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | column -t
```

`printf '%s\n' <items> | column` — Format a list of items into columns for display.

```bash
printf '%s\n' red green blue yellow orange purple | column
```

`<command> | column -t -s $'\t'` — Format tab-separated output into an aligned table.

```bash
docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}' | column -t -s $'\t'
```

## Common Patterns

`cat /etc/passwd | column -t -s ':'` — Display /etc/passwd as a readable aligned table.

```bash
cat /etc/passwd | column -t -s ':'
```

`(head -1 <file> && tail -n +2 <file> | sort) | column -t -s ','` — Sort a CSV file (keeping header) and display as aligned table.

```bash
(head -1 data.csv && tail -n +2 data.csv | sort -t',' -k2) | column -t -s ','
```

`printf '%-15s %s\n' 'Key' 'Value' && printf '%-15s %s\n' <pairs>` — Manual column formatting with printf when column is not flexible enough.

```bash
printf '%-15s %s\n' 'Host' 'example.com' 'Port' '443' 'Protocol' 'HTTPS'
```

`awk -F: '{print $1, $3, $7}' /etc/passwd | column -t` — Select specific fields with awk and format as aligned table.

```bash
awk -F: '{print $1, $3, $7}' /etc/passwd | column -t
```

`column -t -s ',' -o ' | ' <file>` — Convert CSV to a pipe-separated table (Markdown-like).

```bash
column -t -s ',' -o ' | ' data.csv
```

`paste <file1> <file2> | column -t -s $'\t'` — Merge two files side by side and align as table.

```bash
paste names.txt scores.txt | column -t -s $'\t'
```

<!-- PROSE:outro -->
## Conclusion

column turns unreadable data streams into clean tables with a single `-t` – unbeatable for making command output or CSV files scannable in the terminal. Watch out for two pitfalls, though. First, `column` is not the same everywhere – the powerful options (`-N`, `-O`, `-H`, `-J`) come from util-linux and are missing on BSD/macOS, where column is much leaner. Second, with `-s` column does not merge consecutive delimiters by default, so empty fields can show up as separate columns. For pure display column is perfect; for processing data, reach for cut, awk or a proper CSV parser instead.

## Further Reading

- [column(1) man page (util-linux)](https://man7.org/linux/man-pages/man1/column.1.html) – official reference for all options
- [util-linux project](https://github.com/util-linux/util-linux) – the package that provides the modern column implementation
<!-- PROSE:outro:end -->

## Related Commands

- [cut](https://www.jpkc.com/db/en/cheatsheets/files-text/cut/) – extract fields, characters or byte ranges from lines
- [paste](https://www.jpkc.com/db/en/cheatsheets/files-text/paste/) – merge lines of several files column by column
- [sort](https://www.jpkc.com/db/en/cheatsheets/files-text/sort/) – sort lines, often as a step before displaying a table

