|
| 1 | +# The `column` Command |
| 2 | + |
| 3 | +The `column` command is used to format its input into multiple columns. It's particularly useful for making text-based tables and improving the readability of command output. |
| 4 | + |
| 5 | +## Command Syntax |
| 6 | +```bash |
| 7 | +column [options] [file]... |
| 8 | +``` |
| 9 | + |
| 10 | +## Command Options |
| 11 | +- `-t`: Determine the number of columns automatically and create a table |
| 12 | +- `-s`: Specify the column delimiter (default is whitespace) |
| 13 | +- `-n`: Don't merge multiple adjacent delimiters |
| 14 | +- `-c`: Output in column format with specified width |
| 15 | +- `-x`: Fill columns before rows |
| 16 | +- `-L`: Align all entries to the left |
| 17 | +- `-R`: Align all entries to the right |
| 18 | +- `-o`: Specify column separator for table output |
| 19 | + |
| 20 | +## Examples |
| 21 | + |
| 22 | +1. Basic Column Formatting |
| 23 | +```bash |
| 24 | +# Create a simple list and format it into columns |
| 25 | +ls | column |
| 26 | +``` |
| 27 | + |
| 28 | +2. Creating a Table from Delimited Data |
| 29 | +```bash |
| 30 | +# Format /etc/passwd entries into a neat table |
| 31 | +cut -d: -f1,6,7 /etc/passwd | column -t -s: |
| 32 | +``` |
| 33 | + |
| 34 | +3. Formatting Command Output |
| 35 | +```bash |
| 36 | +# Display mount information in a clean tabular format |
| 37 | +mount | column -t |
| 38 | +``` |
| 39 | + |
| 40 | +4. Custom Column Separator |
| 41 | +```bash |
| 42 | +# Format CSV data with custom separator |
| 43 | +echo "Name,Age,City\nJohn,25,NYC\nJane,30,LA" | column -t -s, |
| 44 | +``` |
| 45 | + |
| 46 | +5. Left-aligned Table |
| 47 | +```bash |
| 48 | +# Create a left-aligned table from space-separated data |
| 49 | +ps aux | head -n 5 | column -t -L |
| 50 | +``` |
| 51 | + |
| 52 | +## Additional Information |
| 53 | +- The `column` command is part of the `util-linux` package |
| 54 | +- It's particularly useful in shell scripts for formatting output |
| 55 | +- Can handle both file input and standard input (stdin) |
| 56 | +- Works well with other text processing commands like `cut`, `sort`, and `grep` |
| 57 | + |
| 58 | +## See Also |
| 59 | +- [`cut`](098-the-cut-command.md) - remove sections from files |
| 60 | +- [`sort`](059-the-sort-command.md) - sort lines of text files |
| 61 | +- [`paste`](060-the-paste-command.md) - merge lines of files |
| 62 | +- [`tr`](119-the-tr-command.md) - translate or delete characters |
| 63 | + |
| 64 | +## Further Reading |
| 65 | +- `man column` - manual page for the column command |
| 66 | +- [GNU Coreutils](https://www.gnu.org/software/coreutils/) |
0 commit comments