column

Format output file by columns

Summary

column [options] [file ...]

The main purpose

Parameters

file (optional), when no file is specified, it will be read from standard input by default, so it can be used with the pipe character.

Options

-c, --columns <width> Output width in characters
-t, --table Create a table (characters in each column will be aligned)
-s, --separator <string> Specify the separator to identify the table
-o, --output-separator <string> Column separator of the output table, default is two spaces
-x, --fillrows fill rows before columns
-h, --help show this help
-V, --version output version information

return value

Format the arranged string.

Example

# Generate 26 English letters, one in each column
$ for a in {a..z}; do echo $a; done > test

#Maximum 60 characters per line
$ cat test | column -c 60
a e i m q u y
b f j n r v z
c g k o s w
d h l p t x

# On the basis of the above, further organization, the width between each column defaults to two blank characters
$ cat test | column -c 60 | column -t
a e i m q u y
b f j n r v z
c g k o s w
d h l p t x

# Specify each column to be spliced with ', '
$ cat test | column -c 60 | column -t -o ', '
a, e, i, m, q, u, y
b, f, j, n, r, v, z
c, g, k, o, s, w
d, h, l, p, t, x
# Existing text file test with the following messy content
$ cat test
Address[0] Metal3,pin 133.175:159.92
Address[1] Metal3,pin 112.38:159.92
Address[2] Metal3,pin 70.775:159.92
Address[3] Metal3,pin 41.655:159.92
DataIn[0] Metal3,pin 66.615:159.92
DataIn[1] Metal3,pin 37.495:159.92
DataIn[2] Metal3,pin 122.88:159.92
DataIn[3] Metal3,pin 95.74:159.92
DataOut[0] Metal3,pin 45.815:159.92
DataOut[1] Metal3,pin 79.095:159.92
DataOut[2] Metal3,pin 104.055:159.92
DataOut[3] Metal3,pin 62.46:159.92
MemReq Metal3,pin 108.215:159.92
RdWrBar Metal3,pin 87.415:159.92
clock Metal3,pin 74.935:159.92

# Column alignment
$ cat test | column -t
Address[0] Metal3,pin 133.175:159.92
Address[1] Metal3,pin 112.38:159.92
Address[2] Metal3,pin 70.775:159.92
Address[3] Metal3,pin 41.655:159.92
DataIn[0] Metal3,pin 66.615:159.92
DataIn[1] Metal3,pin 37.495:159.92
DataIn[2] Metal3,pin 122.88:159.92
DataIn[3] Metal3,pin 95.74:159.92
DataOut[0] Metal3,pin 45.815:159.92
DataOut[1] Metal3,pin 79.095:159.92
DataOut[2] Metal3,pin 104.055:159.92
DataOut[3] Metal3,pin 62.46:159.92
MemReq Metal3,pin 108.215:159.92
RdWrBar Metal3,pin 87.415:159.92
clock Metal3,pin 74.935:159.92

# Also recognize ',' and ':' as delimiters
$ cat test | column -t -s ',: '
Address[0] Metal3 pin 133.175 159.92
Address[1] Metal3 pin 112.38 159.92
Address[2] Metal3 pin 70.775 159.92
Address[3] Metal3 pin 41.655 159.92
DataIn[0] Metal3 pin 66.615 159.92
DataIn[1] Metal3 pin 37.495 159.92
DataIn[2] Metal3 pin 122.88 159.92
DataIn[3] Metal3 pin 95.74 159.92
DataOut[0] Metal3 pin 45.815 159.92
DataOut[1] Metal3 pin 79.095 159.92
DataOut[2] Metal3 pin 104.055 159.92
DataOut[3] Metal3 pin 62.46 159.92
MemReq Metal3 pin 108.215 159.92
RdWrBar Metal3 pin 87.415 159.92
clockMetal3 pin 74.935 159.92