|cols||If the output from some program runs down the left-hand side of your screen and takes more than one screen to display, you can pipe the program output to a. If the lines of text are short, you can see more of that text on the screen at once by reformatting the text into columns. The pr command can . But it's not easy to use if you want the input text to be ordered down a column instead of across columns. And it's tough to use if you want as many columns as will fit across your screen - you have to find the widest piece of data before you can figure each column's width.|
Some UNIX systems have a program specifically for making data into columns - but many don't. The cols script takes care of that. It reads your text, finds the widest piece, and chooses pr options to make as many columns as will fit on the screen. cols also has seven other names-named c2, c3, c4, c5, c6, c7, and c8-that make output in 2, 3, 4, 5, 6, 7, or 8 columns. If you call the script with one of those names, it will fill the screen with that number of columns.
For example, to list misspelled words in columns:
spell somefile | colsword1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 word14 word15 word16
By default, like the example above, cols and the others order the input words across the screen; that's the fastest way. If you need output going down each column, use the -d option. Then the scripts will calculate column length and order items down the screen:
spell somefile | cols -dword1 word3 word5 word7 word9 word11 word13 word15 word2 word4 word6 word8 word10 word12 word14 word16
The script will read from files you name; otherwise it reads standard input. It figures your screen width from the COLUMNS environment variable if it's set; otherwise, it callsto read your termcap. (On terminfo systems, use instead of tcap.) If you use a windowing system with adjustable-width windows, the script could be hacked to check the output of stty size or .
A few programming details: the number of columns, nc, is taken from the script name (c2, etc.)-or, if you call cols, the script usesto find the longest input line and calculate the number of columns. (A tests to decide.) does other calculations. Without the -d flag, the pr command line for making the columns is simple:
pr -$nc -t -w$width -l1 $temp
$temp file holds the input text.
With -d, the command line is more complicated.
to count the number of input lines, then expr
to divide by the number of columns and add 1:
pr -$nc -t -w$width -l`expr \( \`wc -l < $temp\` / $nc \) + 1` $temp
wc -l < $temp
will run first.
The line count from wc will be substituted onto the expr command
The result from expr will be glued after the
-l to complete
the pr page length option.
If you don't like condensing the command line that much, you can move the
wc and expr commands to other lines and pass the values with
You can install this script from the CD-ROM or from the. If you get it from the archive, ask tar to install cols and its seven other links:
cols c2 c3 c4 c5 c6 c7 c8x cols, 2160 bytes, 5 tape blocks c2 linked to cols c3 linked to cols ...