column command in Linux with examples

column command in Linux is used to display the contents of a file in columns. The input may be taken from the standard input or from the file. This command basically breaks the input into the multiple columns. Rows are filled before columns. Empty lines from the input are ignored unless the -e option is used.

Syntax:

column [-entx] [-c columns] [-s sep] [file ...]

Example:

  • Suppose you have a text file with the following contents:

  • To display the information of the text file in form of columns, you enter the command:
    column filename.txt

  • Suppose, you want to sort into different columns the entries that are separated by particular delimiters. For example, this sample text file:

  • To separate the column based on the delimiter “|”, you would give the following command, which in turn produces the given output:

  • In case you give multple delimiters(same type), the command treats them as a single one. For example:

  • Upon application of command yields the output:

Options:

  • -J : This option specifies the system to display the output in JSON format.
  • -c : Defines the width of the output based upon the total number of characters allowed in one row.
  • -d : Used to define that the header is NOT to be printed.
  • -N : It defines the column names, and each name is separated by a comma(“, “).
  • -H : It is used to hide the sepecified columns from being displayed.
  • -V : Displays version information and exits.
  • -h : Shows help information and exits.
  • -s : Defines the column delimiter for output.
  • -t : Applied for creating a table by determining the number of columns.
  • -R : Used to right-align text in a specific column.
  • -T : Allows the system to truncate text wherever necessary so that the column width can be adjusted to ensure that the column doesn’t become too wide.
  • -O : Allows the user to define the order in which columns have to be displayed.
  • -L : Inserts empty lines after each row.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.