Display Command Output or File Contents in Column Format

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…

Qadry
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

You might also likeRELATED

How to set PassivePortRange and PassiveIP in pure-ftpd on Ubuntu to secure the app!

Introduction Hi guys, We will talk about setting PassivePortRange and PassiveIP in pure-ftpd. If you run a firewall on your Linux server and want to...

Install Java 8 on CentOS 8

Hi Guys, In this guide, we’ll show you how to install Oracle’s Java 8 programming language on CentOS 8 . It's an object-oriented language...

How to install flameshot on RHEL/CentOS using Snapcraft

In this post, you will learn how to install Flameshot on RHEL / CentOS Flameshot is a powerful open source screenshot and annotation tool for...