I have a program that generates and outputs a sequence开发者_如何转开发 of simple sample math homework tasks, like:
1 + 1 = ...
3 + 3 = ... 2 + 5 = ... 3 + 7 = ... 4 + 2 = ...
a sequence can be quite long, and I'd like to save space when this sequence is printed by converting it as follows:
1 + 1 = ... 3 + 7 = ...
3 + 3 = ... 4 + 2 = ... 2 + 5 = ...
that is, wrapping the lines into the two or more columns. I was expecting the column
linux utility to do the job using the -c N
option witn N=2
, however, it still outputs the lines in one column whatever the N
is.
How would I do the column-ifying of the sequence of lines?
Believe it or not, the utility you want is pr, not columns. If you want your file turned into 3 columns:
pr -3 textfile.txt
If you want to fill in rows first, then columns:
pr -l1 -t -3 textfile.txt
I got these sample invocations from the ever-so-useful UNIX Power Tools. This is Recipe 21.16.
The -c
parameter to column
is used to specify the number of "columns" your display has, counted in characters. The column
tool then figures out the number of "output columns" that fits in the given number of "character columns". Passing a small number of "character columns" will almost always yield a single "output column", because more won't fit in the given number of characters. There does not seem to be a way to pass the number of ouput columns on the command line.
精彩评论