Format output with the column utility

1

The column utility is helpful for taking raw data and formatting it in a way that is easier for humans to comprehend. It can take a single column of data and format it into many equally spaced columns. Alternatively it can format multiple rows of data into tables.

In our first example we have a numfile which contains 20 numbers, one on each line, which we output with cat.

$ cat numfile1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

The output is long and you can quickly see with a larger example that the numbers would scroll off the screen. When we pipe this same output to the column command the output is broken into columns and is evenly distributed across the screen.

$ cat numfile | column1       3       5       7        9      11      13      15      17      19
2       4       6       8       10      12      14      16      18      20

The ‘-t’ option determines the number of columns the input contains and creates a table. This is helpful when you have data where the fields have various lengths. A good example to demonstrate this is the white space delimited output from /etc/mtab.

$ cat /etc/mtabproc /proc proc rw,noexec,nosuid,nodev 0 0
none /sys sysfs rw,noexec,nosuid,nodev 0 0
fusectl /sys/fs/fuse/connections fusectl rw 0 0
none /sys/kernel/debug debugfs rw 0 0
none /sys/kernel/security securityfs rw 0 0
none /dev devtmpfs rw,mode=0755 0 0
none /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
none /dev/shm tmpfs rw,nosuid,nodev 0 0
none /var/run tmpfs rw,nosuid,mode=0755 0 0
none /var/lock tmpfs rw,noexec,nosuid,nodev 0 0
none /var/lib/ureadahead/debugfs debugfs rw,relatime 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,noexec,nosuid,nodev 0 0

With the same output piped to column. the resulting table is much more readable.

$ cat /etc/mtab | column -tproc              /proc                        proc                   rw,noexec,nosuid,nodev            0  0
none              /sys                         sysfs                  rw,noexec,nosuid,nodev            0  0
fusectl           /sys/fs/fuse/connections     fusectl                rw                                0  0
none              /sys/kernel/debug            debugfs                rw                                0  0
none              /sys/kernel/security         securityfs             rw                                0  0
none              /dev                         devtmpfs               rw,mode=0755                      0  0
none              /dev/pts                     devpts                 rw,noexec,nosuid,gid=5,mode=0620  0  0
none              /dev/shm                     tmpfs                  rw,nosuid,nodev                   0  0
none              /var/run                     tmpfs                  rw,nosuid,mode=0755               0  0
none              /var/lock                    tmpfs                  rw,noexec,nosuid,nodev            0  0
none              /var/lib/ureadahead/debugfs  debugfs                rw,relatime                       0  0
binfmt_misc       /proc/sys/fs/binfmt_misc     binfmt_misc            rw,noexec,nosuid,nodev            0  0

Share.
  • krisveneracion112

    My business partners were searching for UK 5000-EN last year and were told about an online platform that has a lot of fillable forms . If you want UK 5000-EN too , here’s https://goo.gl/BQXP3T.