如何在Bash中对齐以空格分隔的表的列? [英] How can I align the columns of a space separated table in Bash?
问题描述
我有一个文件,其中有任意数量的非对齐列,用空格分隔.
I have a file with an arbitrary number of non-aligned columns separated with whitespace.
我想对齐文件的列.
我看过col
命令,它似乎不合适.
I've looked at the col
command, and it doesn't seem appropriate.
我可以编写一个 AWK 脚本,但似乎应该存在一个更明显的命令
I could write an AWK script, but it seems like a more obvious command should exist.
推荐答案
您可能希望column
命令(通常与--table / -t
一起使用)产生基本的表格输出:
You might want the column
command, usually with --table / -t
to produce basic tabular output:
在手册页中:
-t, --table
确定输入包含的列数并创建一个表.默认情况下,列用空格定界,或使用--output-separator选项提供的字符定界.表输出对于漂亮打印很有用.
Determine the number of columns the input contains and create a table. Columns are delimited with whitespace, by default, or with the charac‐ters supplied using the --output-separator option. Table output is useful for pretty-printing.
column -t [file]
# or from stdin
cat file | column -t
# For a quick demonstration, format the output of mount
mount | column -t
column
还有很多其他复杂的选项. man column
了解详情.
column
has a lot of other complex options. man column
for details.
这篇关于如何在Bash中对齐以空格分隔的表的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!