LinuxCommandLibrary

column

Format data into aligned columns

TLDR

Format the output of a command for a 30 characters wide display

$ printf "header1 header2\nbar foo\n" | column [[-c|--output-width]] [30]
copy

Split columns automatically and auto-align them in a tabular format
$ printf "header1 header2\nbar foo\n" | column [[-t|--table]]
copy

Specify the column delimiter character for the --table option (e.g. "," for CSV) (defaults to whitespace)
$ printf "header1,header2\nbar,foo\n" | column [[-t|--table]] [[-s|--separator]] [,]
copy

Fill rows before filling columns
$ printf "header1\nbar\nfoobar\n" | column [[-c|--output-width]] [30] [[-x|--fillrows]]
copy

SYNOPSIS

column [-s sep] [-t] [-x] [-n] [-N name] [-o sep] [-c width] [file ...]

PARAMETERS

-s
    Specify a set of separators to be used to determine column boundaries.

-t
    Determine the number of columns the input contains and create a table. By default, uses whitespace as the separator.

-x
    Fill rows before columns.

-n
    Disable line merging. Useful for data with varying column counts.

-N
    Assign a column name

-o
    Specify an output separator. Defaults to two spaces.

-c
    Specify table output width. Columns that exceed it are truncated or wrapped.

[file ...]
    One or more input files to process. If omitted, column reads from standard input.

DESCRIPTION

The column command formats input into multiple columns. It reads from standard input or files specified as arguments and arranges the input into a table-like structure. column can determine the number of columns automatically or accept a user-specified number. It's useful for making data more readable and presentable, especially when dealing with delimited text or text files that need to be neatly aligned. The command can handle different delimiters and output formats, making it a versatile tool for text processing and data manipulation. Input data is usually separated by whitespace by default, but this can be overridden with the delimiter option. column is often used in scripts and pipelines to enhance the presentation of output before displaying it to the user or storing it in a file. It aligns data based on whitespace or specified separators. The primary function is to make textual data easier to read by arranging it into columns.

CAVEATS

column may struggle with very complex or inconsistent data structures, especially if the delimiter is not well-defined or whitespace is inconsistent. For highly complex data manipulation, consider using tools like awk or sed.

EXAMPLES

  • Format a file with comma-separated values: column -s ',' -t file.csv
  • Format output of another command: ls -l | column -t
  • Specify output separator: column -s ':' -o '|' -t data.txt

HISTORY

The column command has been present in Unix-like systems for a long time, dating back to early versions of Unix. Its purpose has always been to format text into aligned columns for improved readability. Over time, variations and extensions have been added to handle different delimiters and output formats. Usage has remained consistent: formatting data for display and processing.

SEE ALSO

expand(1), pr(1), sed(1), awk(1)

Copied to clipboard