column
文本处理
用法
column -t [file]给字段补空格让各列对齐成表格;连续的分隔符只算一个,所以有空单元格的 CSV 会整行错位。
常用选项
| 选项 | 含义 |
|---|---|
| -t | Work out the columns and line them up as a table |
| -s | Which characters separate the input columns, with -t |
| -x | Fill columns before rows |
| -c | Format for a display this many characters wide |
| -o | util-linux: what to put between the output columns |
示例
mount | column -tLines the mount table up.
column -t -s, data.csvReads a CSV into aligned columns.
ls | column -xPrints the listing in columns across the screen.
它们本来就是用管道串起来用的。串三条往往比让一条命令做完所有事更短。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. column 是做什么的?
给字段补空格让各列对齐成表格;连续的分隔符只算一个,所以有空单元格的 CSV 会整行错位。
Q. 怎么写?
column -t [file] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 5 个,完整列表在 man column。这条命令属于文本处理。
相关命令
man 手册: man column