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.
To understand more clearly, we have created a following file “rootadminz-authors.txt” which contains a list of top 5 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 rootadminz-authors.txt file.
$ cat rootadminz-authors.txt
Sample Output -------------------------------- pos|author|articles|comments 1|vyga|741|9785 2|sreelal|679|7894 3|anita|914|2349 4|jarvis|842|3256 5|anupama|128|2378
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 rootadminz-authors.txt | column -t -s "|"
Sample Output ----------------------------------------- pos author articles comments 1 vyga 741 9785 2 sreelal 679 7894 3 anita 914 2349 4 jarvis 842 3256 5 anupama 128 2378
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.
For more information, see the columns man page:
$ man column