Last Updated : 06 Sep, 2024
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 WorksThe '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:
sample file Example 1: Basic Column DisplayTo display the information of the text file in form of columns, you enter the command:
column filename.txtdisplays result 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:
Sample text fileTo separate the column based on the delimiter "|", you would give the following command, which in turn produces the given output:
output based on delimiter specified Example 3: Handling Multiple DelimitersIn case you give multiple delimiters(same type), the command treats them as a single one. For example:
sample text fileUpon application of command yields the output:
Output(with multiple delimiters of same type) Options for the 'column' CommandThe 'column' command comes with a variety of options that allow you to control the formatting and display of data:
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4