How to Format Text into Aligned Tables in Linux Using the column Command

Working with comma-separated values (CSV), tab-delimited files, or system configuration databases like /etc/passwd directly in the Linux terminal frequently yields visual chaos. Because field lengths vary dramatically from row to row, raw text wraps awkwardly across the terminal screen, making columnar data nearly impossible to scan or audit with the naked eye.

The standard Linux column utility (part of the essential util-linux package) solves this instantly. With a single flag, column parses variable-length input streams and recalculates horizontal spacing, rendering cleanly aligned tabular columns. In this guide, we explore how to format raw text with the column command, specify custom input and output delimiters, define custom table headers, and even output structured JSON.

Why Use the column Command

While utilities like awk and cut excel at extracting specific fields by index, they do not dynamically measure maximum column widths across an entire file to calculate uniform spacing. The column command measures every token, determines the widest element in each column, and pads every field with the exact number of spaces needed to establish straight vertical lines.

Key capabilities include:

  • Delimiter Translation: Converts difficult-to-read delimiters (like colons or pipes) into clean whitespace or styled table borders.
  • Header Creation: Appends named titles to unlabelled data streams on the fly.
  • Terminal Awareness: Automatically adapts spacing to fit your current terminal viewport width.

Auto-Formatting Text into Clean Tables (-t Option)

The most widely used flag in column is -t (table mode). By default, column -t treats any sequence of consecutive whitespace (spaces or tabs) as column boundaries:

column -t data.txt

If your source text is jagged and uneven:

Server01 Up 99.8% London
BackupDatabase Down 0.0% Frankfurt
AppGateway-Prod Up 100.0% Amsterdam

Running column -t formats it into clean, readable columns:

Server01          Up    99.8%   London
BackupDatabase    Down  0.0%    Frankfurt
AppGateway-Prod   Up    100.0%  Amsterdam

Specifying Input Delimiters (-s Option)

Many system configuration files and spreadsheets use specific characters rather than spaces to separate fields. Use the -s option followed by the separator character to tell column how to parse the records.

For example, to display the colon-delimited Linux user database (/etc/passwd) as a readable table:

column -t -s ":" /etc/passwd | head -n 10

To format a standard CSV file where columns are divided by commas:

column -t -s "," customers.csv | less -S

(Tip: Passing less -S prevents long rows from wrapping, allowing you to scroll horizontally using the arrow keys.)

Customising Output Separators (-o Option)

By default, column separates aligned columns with two spaces. If you want to generate Markdown-ready tables or visually striking terminal reports, you can specify a custom output separator using the -o flag:

column -t -s "," -o " | " sales_report.csv

This transforms a raw CSV export into a clean, pipe-delimited table layout:

Quarter | Region | Target | Revenue
Q1      | North  | 50000  | 54200
Q2      | North  | 55000  | 51900
Q3      | South  | 42000  | 46800

Adding Custom Column Header Names (-N Option)

Many raw system streams (like ls -l or ss -tuln) lack descriptive column headers. The modern column utility allows you to supply custom header labels using the -N (or --table-columns) option:

cat /etc/passwd | cut -d: -f1,3,4,6,7 | column -t -s ":" -N "USERNAME,UID,GID,HOME,SHELL" -o " | "

This command automatically injects an aligned header row across the top of your output, creating a professional audit report directly in your terminal.

Exporting Formatted Tables as JSON (-J Option)

In automated administration and CI/CD pipelines, converting plain text outputs into structured JSON for ingestion by Python, jq, or web dashboards usually requires complex regex parsing. The column command features native JSON serialization using the -J flag combined with -N:

cat servers.txt | column -t -s ":" -N "hostname,ip,status" -J

This automatically produces valid JSON formatted as:

{
   "table": [
      {
         "hostname": "web-01",
         "ip": "10.0.1.5",
         "status": "active"
      },
      {
         "hostname": "db-01",
         "ip": "10.0.1.9",
         "status": "standby"
      }
   ]
}

Real-World Shell Pipeline Examples

Because column reads from standard input, it can enhance almost any standard Unix command:

  • Align Filesystem Mounts:
    mount | column -t
    Converts the chaotic output of the mount command into neatly aligned device, mountpoint, and filesystem columns.
  • Format Active Listening Ports:
    ss -tuln | column -t
    Neatly separates Netid, State, Local Address:Port, and Peer Address:Port.
  • Clean Up Environment Variables:
    printenv | column -t -s "=" -o " => " | sort | less
    Presents every active environment variable as an aligned key-value pair.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.