Run the cat command below to view the rootadminz-authors.txt file.

$ cat ucartz-authors.txt
Sample Output

pos|author|articles|comments
1|ebin|895|8454
2|vyga|785|6785
3|rahul|458|4529

Using the column command, we can display a much clear output as follows, where the -t helps to determine the number of columns the input contains and creates a table and the -s specifies a delimiter character.

$ cat ucartz-authors.txt  | column -t -s "|"
Sample Output

pos       author       articles      comments
1           ebin            895           8454
2           vyga           785           6785
3           rahul           458           4529

 

By default, rows are filled before columns, to fill columns before filling rows use the -x switch and to instruct column command consider empty lines (which are ignored by default), include the -e flag.

Here is another practical example, run the two commands below and see difference to further understand the magic column can do

$ mount
$ mount | column -t
Sample Output
sysfs        on  /sys                             type  sysfs            (rw,nosuid,nodev,noexec,relatime)
proc         on  /proc                            type  proc             (rw,nosuid,nodev,noexec,relatime)
udev         on  /dev                             type  devtmpfs         (rw,nosuid,relatime,size=4013172k,nr_inodes=1003293,mode=755)
devpts       on  /dev/pts                         type  devpts           (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs        on  /run                             type  tmpfs            (rw,nosuid,noexec,relatime,size=806904k,mode=755)
/dev/sda10   on  /                                type  ext4             (rw,relatime,errors=remount-ro,data=ordered)
securityfs   on  /sys/kernel/security             type  securityfs       (rw,nosuid,nodev,noexec,relatime)
tmpfs        on  /dev/shm                         type  tmpfs            (rw,nosuid,nodev)
tmpfs        on  /run/lock                        type  tmpfs            (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs        on  /sys/fs/cgroup                   type  tmpfs            (rw,mode=755)
cgroup       on  /sys/fs/cgroup/systemd           type  cgroup           (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/
....

To save the nicely formatted output in a file, use the output redirection as shown.

$ mount | column -t >mount.out

 

Hjälpte svaret dig? 0 användare blev hjälpta av detta svar (0 Antal röster)