39
votes

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.

1
@CiroSantilli新疆改造中心六四事件法轮功: It's more like that question is a duplicate of mine, since it was asked more than a year later. But it does have helped information - thanks for making the association!Richard
Hey Richard, the current consensus is to close by "quality": meta.stackexchange.com/questions/147643/… Since "quality" is not measurable, I just go by upvotes. ;-) Likely it comes down to which question hit the best newbie Google keywords on the title. It is sometimes random :-(Ciro Santilli 新疆再教育营六四事件法轮功郝海东

1 Answers

74
votes

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.