The column
is a really helpful Linux command-line utility that may show you how to to view a single lengthy record of output information in a number of columns in a terminal. With varied choices obtainable for a column, you may also use it to format information and do extra than simply columnating it.
Let’s see how we are able to successfully use the Linux Column command in a terminal to remain extra productive.
10 Methods To Use Column Command In Linux
1. Show Information In Column
Suppose you wish to record all binaries from /usr/bin/
, whose identify begins with b. In case you run the command with out utilizing column, it will provide you with all output in a single column.
Now, in case you pipe the output from the final command to column utility, you possibly can see the beneath output.
Did you see the distinction column
deliver? Column merely distributed a single record of output into a number of columns. Now you can view all output on a display at a time with out scrolling down.
You probably have a protracted record of content material in your file, then you may also use column command to show extra information on a display utilizing the command:
$ column <filename>
2. Show Information In A Tabular Type
If you’d like a transparent view of your enter information in a tabular kind the place columns are delimited with whitespace or different characters, Column utility has a -t
or --table
possibility.
It creates a desk by figuring out the variety of columns enter accommodates utilizing a delimiter.
3. Delimited Output Information
Suppose you get the enter information within the following kind.
Now you wish to view output information in a desk kind however with column separated by whitespace rather than “|” delimiter. You need to use the column command’s -s
or --separator
possibility that separates the desk column based mostly on the delimiter you go.
$ column <filename> -t -s "<delimiter>"
4. Output Information Separator
As you noticed within the earlier instance, utilizing -s
possibility column creates a desk with column separated by whitespaces. However what if you’d like column within the output information separated by another character as a substitute of the default two areas?
For a similar, Column has -o
or --output-separator
choices that you should utilize to specify your column delimiter for desk output.
$ column <filename> -t -s "<character-to-be-replace>" -o "<new-delimiter>"
5. Output Information With Customized Column Title
Typically you get enter information with no column identify or header that specify columns in a desk.
In such a case you should utilize -N
or --table-columns
possibility to provide logical column names separated by commas within the command line. In case you specify the column identify for columns that don’t exist within the desk, a desk will nonetheless make area for it.
$ column <filename> -t --table-columns <columns-names>
6. Show Output In JSON Format
As a substitute of column and desk format, the Linux Column utility additionally gives an possibility -J
or --json
to show output in JSON format.
To print JSON output, you could have to specify column identify utilizing --table-columns
.
$ column <filename> -t --json --table-columns <columns>
As you possibly can see within the above image, column command provides “desk” because the default identify for JSON output. Utilizing -n
or --table-name
, you may also give a customized desk identify for it.
7. Change Output Orientation
By default, column print output information following the column to row mode. This implies, it first fills the column earlier than rows.
However if you wish to reverse it to fill the primary rows after which columns, you should utilize -x
or --fillrows
possibility.
8. Present Output With Empty Traces
In case your enter information accommodates an empty line with whitespace solely, it’s most probably that it is going to be ignored by column command by default.
Therefore, if you wish to hold that traces with whitespace within the output show, it’s good to use -L
or --table-empty-lines
possibility.
$ column <filename> -t --table-empty-lines
9. Reorder Column Place
If you wish to reorder the column place, the Linux column command additionally has an possibility -O
or --table-order
to specify column order on output.
$ column <filename> -t --table-columns <columns> --table-order <reordered-columns>
10. Cover Columns
Need to cover specified columns? you should utilize -H
or --table-hide
possibility with column command.