column command in Linux with examples
The 'column' command in Linux is a powerful utility used to format text input into organized columns, making it easier to read and analyze data. This command can take input from a file or standard input, and it arranges the data into columns by breaking up the text and distributing it across rows and columns. The command fills rows before filling columns, and it can be customized with various options to adjust how the output is displayed.
How the 'column' Command Works
The 'column' command reads data line by line and arranges it into a tabular format, filling rows first before moving on to the next column. This formatting approach makes the data more structured and easier to view, especially when dealing with text that contains tabular data. Empty lines are ignored by default unless the '-e' option is used, which includes them in the output.
Syntax:
column [-entx] [-c columns] [-s sep] [file ...]
Examples of Using the 'column' Command
Suppose you have a text file with the following contents:

Example 1: Basic Column Display
To display the information of the text file in form of columns, you enter the command:
column filename.txt

Example 2: Using a Specific Delimiter
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:

Example 3: Handling Multiple Delimiters
In case you give multiple delimiters(same type), the command treats them as a single one. For example:

Upon application of command yields the output:

Options for the 'column' Command
The 'column' command comes with a variety of options that allow you to control the formatting and display of data:
- '-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 specified 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.
Conclusion
The 'column' command in Linux is a versatile tool that simplifies the task of organizing data into a readable columnar format. With various options for customizing the display, including JSON output, right alignment, and custom delimiters, 'column' is perfect for data analysis, scripting, and any scenario where structured text presentation is needed. By mastering the 'column' command, you can make data more accessible and improve the overall usability of your command-line output.