Column

From Leo's Notes
Last edited on 18 August 2023, at 21:59.

Column is a utility that formats data into neat columns. Rather than relying on inserting the proper number of spaces or tabs, you can pipe your output through column to have the output look spectacular.

Usage

Just pipe whatever you want columnized through column -t and it will format it into a nice table.

% for i in apple orange banana pear ; do echo $i "\$0.00" ; done | column -t
apple   $0.00
orange  $0.00
banana  $0.00
pear    $0.00

Example applications

Watch Linux port counters

Although the Receive/Transmit lines are mismatched (on the first line), it is a lot easier to read this than the raw output from /proc/net/dev. I typically then watch the port counters in conjunction with the watch command: watch -d -n 1 "cat /proc/net/dev | tr '|' ' ' | column -t"

Example output:

# cat /proc/net/dev | tr '|' ' ' | column -t
Inter-    Receive          Transmit
face      bytes            packets       errs  drop     fifo  frame  compressed  multicast  bytes            packets       errs  drop  fifo  colls  carrier  compressed
lo:       5217334816196    1656330248    0     0        0     0      0           0          5217334816196    1656330248    0     0     0     0      0        0
eno3:     12385201379767   10995758725   0     1031     0     0      0           162175103  495954146757     4117060272    0     0     0     0      0        0
eno4:     0                0             0     0        0     0      0           0          0                0             0     0     0     0      0        0
eno1np0:  85133723077447   101269770828  0     0        0     0      0           1574       167232033724542  129467009423  0     0     0     0      0        0
eno2np1:  437322690750946  211939829225  0     8768343  0     0      0           17         311757943459204  148155482836  0     0     0     0      0        0
ib0:      82821062753028   51292209226   0     0        0     0      0           0          45818958606850   37295454471   0     0     0     0      0        0
ib1:      0                0             0     0        0     0      0           0          0                0             0     0     0     0      0        0