Linux Commands

Linux Column Command

While using Linux distributions, some of the data needs to be displayed in columnar format. Linux system makes it easy to display content in columns using the “column” command.

The “column” command is a simple command-line utility to print the file contents in columns. This command-line tool supports multiple options containing proper functionality that are worth considering.

When using the “column” command in a terminal, it ignores blank lines by default.

If we have data displayed in multiple columns, the command will start to display the data from the left side to the right side i-e; it will begin to add content in the left column first and then move towards the right columns.

Syntax of Column Command:

The syntax of the Linux “column” command is:

“column [-entx] [-c columns] [-s sep] [file name…]

Column Command Options:

Let’s create a file named “test.txt” and add some content to it.

For example, we have some content in the “test.txt” file.

So, the output of this text file should be printed in columns. Type the column command with the file name, and your output would be:

$ column test.txt

D:\Warda\march\18\Linux Column Command Tutorial\Linux Column Command Tutorial\images\image4 final.png

If you have content in a file where a particular delimiter separates entries, use the “-s” option with “-t.”

When we use this command, it will remove the delimiter and produce output in a columnar format.

Let’s see how this option works. For example, we have a file “file.txt” containing the following data with delimiter “|”:

Now, use the following command to check the output:

$ column file.txt -t -s|

D:\Warda\march\18\Linux Column Command Tutorial\Linux Column Command Tutorial\images\image6 final.png

To print a help message related to the “column” command, use the “–help” command, and it shows all options in the terminal with functions.

$ column --help

D:\Warda\march\18\Linux Column Command Tutorial\Linux Column Command Tutorial\images\image5 final.png

Check the version of the “column” command using the “–version” option.

$ column --version

D:\Warda\march\18\Linux Column Command Tutorial\Linux Column Command Tutorial\images\image1 final.png

Other Useful Options of Column Command:

  • -R: This option is used to apply the right alignment in a particular column.
  • -J: To print output in a JSON format, use the “-j” option with the file name.
  • -d: Use this command, and it will show you that header is not to be displayed in the output.
  • C: It helps determine the width of output and how many characters can print in a single row.
  • -N: Use to print column names separated by a comma “,
  • -L: It is used to add empty lines after every row.
  • -O: It defines the order of columns in which the data will be displayed.

Conclusion:

The “column” command is a command-line utility introduced by the Linux system to display output in a columnar format. This guide discussed column command briefly and learned how to use it with different options.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.