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”...

Spread the love

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.

Facebook Comments

More Stuff

How to figure out the best pricing for your SaaS You just finished building your MVP. Now you’re looking to launch and start getting paying customers. The problem is, you have no idea how you sh...
Apple’s new AirPods come with a wireless charging case, Hey Siri s... Apple’s week of surprise product launches continues with the announcement of the second-generation AirPods, which will include a wireless charging cas...
How to Transform and Build a People Platform To the casual spectator, Facebook is having a terrible year. Besieged by privacy scandals, the company was torn into by Congress, the press, and the p...
What Is a Bot? Our in-house Know-It-Alls answer questions about your interactions with technology. Q: What is a bot? A: It’s a sunny day outside, but you wouldn’t ...
Spread the love

Posted by News Monkey