Parsing Tabular Output in Linux With column
The Linux column command, provided by the
util-linux package, is a dedicated command-line utility
designed to format unstructured text, delimited streams, and lists into
neatly aligned tabular structures. This article explains how the Linux
operating system uses the column command to process tabular
data, covering its core parsing flags, delimiter handling, header
injection, and modern structured output generation like JSON.
Core Mechanics of the column Command
The column utility reads from standard input (stdin) or
a specified file and dynamically calculates whitespace padding to align
text along vertical axes. By default, it organizes input lines into
multiple columns to fit the width of the terminal.
To display standard terminal commands in a clean table, pipe output
directly into column:
mount | column -tThe -t (table) option tells column to
determine the number of columns the input contains and generate an
aligned table rather than simply wrapping words across the screen.
Parsing Delimited Data
Raw system data often relies on delimiters such as commas, tabs, or
colons. The column command manages these formats using two
primary flags:
- Input Delimiter (
-s): Defines the character or string used to separate fields in the raw input. - Output Delimiter (
-o): Specifies the string inserted between columns in the rendered table (defaults to two spaces).
Example: Parsing Colon-Separated Files
System files like /etc/passwd use colons to separate
user attributes. To parse this into an aligned table:
column -s ":" -t /etc/passwdExample: Customizing Output Delimiters
To retain a specific separator (such as a vertical pipe
|) while standardizing spacing, combine -s
with -o:
column -s "," -o " | " -t data.csvAdding and Managing Column Headers
Linux users can assign readable column labels directly through the command line without modifying the underlying raw data.
The -N option defines a comma-separated list of column
names:
cat /etc/group | column -s ":" -t -N "Group Name,Password,GID,Users"To underline or format these headers visually in terminal
environments, the -H option can hide specific headers or
apply standard table formatting styles supported by the terminal.
Column Alignment and Truncation
Modern implementations of column allow control over text
alignment per column:
- Right Alignment (
-R): Useful for numeric data. Specify column numbers or names to right-align them.
cat disk_usage.txt | column -t -R 2,3,4- Text Wrapping and Limits (
-W): Wraps text inside designated columns instead of extending beyond terminal boundaries.
column -t -W Description data.txtModern Script Integration: JSON Output
Recent versions of the util-linux suite allow
column to export structured JSON using the -J
flag. When combined with -t and -N,
column converts raw delimited streams into structured data
suitable for automated parsing by tools like jq or external
APIs:
cat /etc/passwd | column -s ":" -t -N "user,pass,uid,gid,comment,home,shell" -JThis bridge between unstructured shell streams and modern data
interchange formats makes column an effective tool for both
visual inspection and data pipeline normalization in Linux.