40 C
Jaipur
Tuesday, April 13, 2021

Linux Column Command – Linux Hint

Must read

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:

D:Wardamarch18Linux Column Command TutorialLinux Column Command Tutorialimagesimage4 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:Wardamarch18Linux Column Command TutorialLinux Column Command Tutorialimagesimage6 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.

D:Wardamarch18Linux Column Command TutorialLinux Column Command Tutorialimagesimage5 final.png

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

D:Wardamarch18Linux Column Command TutorialLinux Column Command Tutorialimagesimage1 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.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article