How do I convert a single column to 3 columns?

A solution with paste

seq 10 | paste - - -
1       2       3
4       5       6
7       8       9
10

paste is a Unix standard tool, and the standard guarantees that this works for at least 12 columns.


The columns tool can do this:

$ seq 10 | columns -W 16 -c 3
1     2     3
4     5     6
7     8     9
10

-W 16 is just to set the line width to something small.

columns is not a Unix standard tool. It is part of GNU AutoGen.

Some versions of the more common column command may be able to set the number of columns with -c, but modern versions seem to have changed its meaning to set the line width by number of characters.

There's also pr as suggested by mpez0 in a comment:

$ seq 10 | pr -aT3
1           2           3
4           5           6
7           8           9
10

-aT3 is short for --across --omit-pagination --columns=3.

pr is in coreutils and POSIX, though -T/--omit-pagination seems to be GNU-specific.


Try like

seq 1 10 | awk '{printf "%40s", $0} !(NR%3) {printf "\n"}'
                                       1                                       2                                       3
                                       4                                       5                                       6
                                       7                                       8                                       9
                                      10