The column
command in Bash is used to format text input into neatly aligned columns. It is particularly useful for organizing data output from other commands or files, making it easier to read and interpret.
The basic syntax of the column
command is as follows:
column [options] [arguments]
-t
: Create a table by determining the number of columns based on whitespace.-s <char>
: Specify a delimiter character to separate columns (default is whitespace).-n
: Suppress the output of the column header.-x
: Fill columns before filling rows, which can be useful for certain layouts.To format a simple list of items into columns:
echo -e "Name\nAlice\nBob\nCharlie" | column
If you have a CSV file and want to format it using a comma as a delimiter:
cat data.csv | column -s, -t
You can create a table from space-separated values:
echo -e "ID Name\n1 Alice\n2 Bob\n3 Charlie" | column -t
To fill columns before rows, you can use the -x
option:
echo -e "A\nB\nC\nD\nE\nF" | column -x
-t
option for better readability when dealing with space-separated data.cat
or redirection to pipe the contents into column
.-s
option to see what works best for your data format.