Display Command Output or File Contents in Column Format

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

This article will show you how to display command output or a file content in a column format to clarify and demonstrate the output.

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.

Display output in column format

We have a file called name.txt which contains a list of random names with their location and the id.

So view it with cat command

cat names.txt
  • Use the column command to display a clear and demonstrated output as shown below.

“-t “:to determine the number of columns the input contains and creates a table .

“-s” to specify a delimiter character.

cat names.txt | column -t -s "|"
  • Also you can demonstrate the /etc/passwd file
cat /etc/passwd
  • Make sure that you are using the right delimiter which here is “:”
cat /etc/passwd | column -t -s ":"

NOTE: rows are filled before columns by default, to fill columns before filling rows use the -x switch and to instruct column command consider empty lines, include the -e flag.

  • Another example with mount command to demonstrate its output.
mount
mount | column -t
  • You can see more info by displaying the man page of column
man column

Conclusion

In this short guide, we illustrated how to display command output or file contents in column format.

Thank you…

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook