Linux column Command
column is a practical command-line tool in Linux used to format input text into multiple columns. It can reorganize messy text data into a neat tabular form, greatly improving readability.
Typical use cases:
- Format command output (such as
ls,psetc.) - organize CSV or TSV data
- create simple terminal tables
- align log file content
Basic Syntax
column [选项] [文件名]
If no filename is specified,column it reads data from standard input.
Commonly used options
| Option | Description |
|---|---|
-t |
Automatically detect the input delimiter and create a table |
-s sep |
Specify a custom column delimiter (whitespace by default) |
-c width |
Set the total output width (in characters) |
-x |
Fill rows before filling columns (columns before rows by default) |
-o sep |
Specify the output column delimiter (two spaces by default) |
-N names |
Specify names for the columns (comma-separated) |
-n |
Do not merge multiple consecutive delimiters |
Usage examples
Basic table formatting
Example
$
echo
-e
"Name Age GendernAlice 25 FnBob 30 MnCharlie 22 M"
|
column
-t
Name Age Gender
Alice
25
F
Bob
30
M
Charlie
22
M
Handle CSV data
Example
$
echo
-e
"ID,Name,Departmentn101,Alice,Salesn102,Bob,IT"
|
column -s,
-t
ID Name Department
101
Alice Sales
102
Bob IT
Custom output delimiter
Example
$
echo
-e
"1 2 3n4 5 6"
|
column
-t
-o
" | "
1
|
2
|
3
4
|
5
|
6
Use in combination with other commands
Example
$
ls
-l
|
head
-5
|
column
-t
total
48
drwxr-xr-x
2
user user
4096
Jan
10
09:
30
Desktop
drwxr-xr-x
2
user user
4096
Jan
10
09:
30
Documents
drwxr-xr-x
2
user user
4096
Jan
10
09:
30
Downloads
Advanced usage
Handle irregular data
Example
$
echo
-e
"Item:Price:StocknApple:1.2:50nOrange:0.8:30"
|
column -s:
-t
Item Price Stock
Apple
1.2
50
Orange
0.8
30
Specify column names
Example
$
echo
-e
"Alice 25nBob 30"
|
column
-N
"Name,Age"
-t
Name Age
Alice
25
Bob
30
Control output width
Example
$
echo
-e
"1 2 3 4 5n6 7 8 9 10"
|
column
-c
30
-t
1
3
5
7
9
2
4
6
8
10
Notes
- Delimiter handling: by default,
columnit treats multiple consecutive whitespace characters as one delimiter; using-nthe option can disable this behavior - Special characters: if the data contains delimiters such as spaces or tabs, it is recommended to specify the delimiter explicitly
- Performance considerations: when processing large files,
columnit may require more memory - Alignment: all columns are left-aligned by default, and specifying the alignment directly is not currently supported
Alternative comparison
| Tool | Advantages | Disadvantages |
|---|---|---|
column |
Simple and easy to use, built into Linux | Rather basic functionality |
awk |
Highly flexible and powerful | Complex syntax |
pr |
Supports paging and column control | Complex options |
paste |
Suitable for merging columns from files | Limited formatting capability |
Practical Exercise
- Format the first 5 lines of your
/etc/passwdfile as a table (hint: use:as the delimiter) - Try using the
columncommand to organize your process list (ps auxoutput) - Create a text file with three columns of data and experiment with
-sthe effect of different delimiter options
Example
Sample solution for Exercise 1
head
-5
/
etc
/
passwd
|
column -s:
-t
By mastering column command, you can easily convert messy text data into an easy-to-read tabular form, which is very practical in everyday system administration and data processing.
Linux Command Reference