开发者

How can I align the columns of a space separated table in Bash? [duplicate]

This question already has answers here: How can I align the columns of tables in Bash? (11 answers) 开发者_C百科 Closed 4 years ago.

I have a file with an arbitrary number of non-aligned columns separated with whitespace.

I would like to align the columns of the file.

I've looked at the col command, and it doesn't seem appropriate.

I could write an AWK script, but it seems like a more obvious command should exist.


You might want the column command, usually with --table / -t to produce basic tabular output:

From the man page:

 -t, --table 

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 has a lot of other complex options. man column for details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜