首页·终端命令

column

文本处理

用法

column -t [file]

给字段补空格让各列对齐成表格;连续的分隔符只算一个,所以有空单元格的 CSV 会整行错位。

常用选项

选项含义
-tWork out the columns and line them up as a table
-sWhich characters separate the input columns, with -t
-xFill columns before rows
-cFormat for a display this many characters wide
-outil-linux: what to put between the output columns

示例

mount | column -t

Lines the mount table up.

column -t -s, data.csv

Reads a CSV into aligned columns.

ls | column -x

Prints the listing in columns across the screen.

它们本来就是用管道串起来用的。串三条往往比让一条命令做完所有事更短。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. column 是做什么的?

给字段补空格让各列对齐成表格;连续的分隔符只算一个,所以有空单元格的 CSV 会整行错位。

Q. 怎么写?

column -t [file] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man column。这条命令属于文本处理。

相关命令

man 手册: man column