Display Command Output or File Contents in Column Format

Are you fed up of viewing congested command output or file content on the terminal. This short article will demonstrate how to display command output or a file content in a much clear “columnated” format.

We can use the column utility to transform standard input or a file content into tabular form of multiple columns, for a much clear output.

Read Also: 12 Useful Commands For Filtering Text for Effective File Operations in Linux

To understand more clearly, we have created a following file “tecmint-authors.txt” which contains a list of top 10 authors names, number of articles written and number of comments they received on the article till now.

To demonstrate this, run the cat command below to view the tecmint-authors.txt file.

$ cat tecmint-authors.txt
Sample Output
pos|author|articles|comments
1|ravisaive|431|9785
2|aaronkili|369|7894
3|avishek|194|2349
4|cezarmatei|172|3256
5|gacanepa|165|2378
6|marintodorov|44|144
7|babin lonston|40|457
8|hannyhelal|30|367
9|gunjit kher|20|156
10|jesseafolabi|12|89

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 tecmint-authors.txt  | column -t -s "|"
Sample Output
pos  author         articles  comments
1    ravisaive      431       9785
2    aaronkili      369       7894
3    avishek        194       2349
4    cezarmatei     172       3256
5    gacanepa       165       2378
6    marintodorov   44        144
7    babin lonston  40        457
8    hannyhelal     30        367
9    gunjit kher    20        156
10   jesseafolabi   12        89

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

For more information, see the columns man page:

$ man column 

You might also like to read these following related articles.

  1. How to Use Awk and Regular Expressions to Filter Text or String in Files
  2. How to Find and Sort Files Based on Modification Date and Time in Linux
  3. 11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

If you have any question, use the comment form below to write to us. You can as well share with us any useful command line tips and tricks in Linux.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply
  1. I asked someone what am I missing about the mount command, couldn’t figure it out. … mount what
    also, errors file does not exist if using > to send to a file

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.