cols [options] [file] |
-h,--help | print this help and exit |
-H,--Help | print full documentation via less and exit |
-V,--version | print version and exit |
-a,--across | print row by row; default: column by column |
-c,--columns=X | print in X columns; the default is to print as |
many columns as fit in the width of the window | |
-s,--squeeze | remove vertical white until the minimum separation between |
columns is the separator string defined by the --sep option | |
-w,--width=X | pretend the window width to be X characters |
--sep=X | separate columns with the string X; default: one space |
--pre=X | prefix each line with the string X |
--suf=X | add the string X as a suffix to each line |
-[1-9] | -1, -2, ... -9 is equivalent to -c 1, -c 2, ... -c 9 |
--width
option was used, the width set by that option. The words are written column by column:
$ seq 13|cols --width=20 1 3 5 7 9 11 13 2 4 6 8 10 12
With the --across
option, cols writes the words row by row:
$ seq 13|cols --width=20 --across 1 2 3 4 5 6 7 8 9 10 11 12 13
The number of columns can be explicitly set with the --columns
option:
$ seq 5 10 133 |cols --columns=4 5 45 85 125 15 55 95 25 65 105 35 75 115
The excessive whitespace can be cut out with the --squeeze
option:
$ seq 5 10 153 |cols -4s 5 45 85 125 15 55 95 135 25 65 105 145 35 75 115
The --sep
, --pre
, and --suf
can, for example, be used to create the contents of a LaTeX table. This one is prefixed with '%␣'
for a .dtx
file:
$ ls / | cols --pre='% ' --sep=' & ' --suf='\\\\' % bin & initrd.img.old & opt & usb1 \\ % boot & lib & proc & usb2 \\ % cdrom & lib32 & root & usr \\ % cj & lib64 & run & var \\ % dev & local & sbin & vmlinuz \\ % etc & lost+found & selinux & vmlinuz.old \\ % fotos & media & srv & wd \\ % ftp & mnt & store & www \\ % home & music & sys & \\ % initrd.img & nrc & tmp & \\
The width of each column is fixed to the width of the widest column. The --squeeze
option removes the excess white space:
$ ls / | cols --pre='% ' --sep=' & ' --suf='\\\\' --squeeze % bin & initrd.img.old & opt & usb1 \\ % boot & lib & proc & usb2 \\ % cdrom & lib32 & root & usr \\ % cj & lib64 & run & var \\ % dev & local & sbin & vmlinuz \\ % etc & lost+found & selinux & vmlinuz.old\\ % fotos & media & srv & wd \\ % ftp & mnt & store & www \\ % home & music & sys & \\ % initrd.img & nrc & tmp & \\
This gives room for one or two extra columns, by using the --columns=6
option; this can be shortened to -6
, and we can even include the shorthand for --squeeze
:
$ ls / | cols --pre='% ' --sep=' & ' --suf='\\\\' -s6 % bin & ftp & local & proc & sys & vmlinuz.old\\ % boot & home & lost+found & root & tmp & wd \\ % cdrom & initrd.img & media & run & usb1 & www \\ % cj & initrd.img.old & mnt & sbin & usb2 & \\ % dev & lib & music & selinux & usr & \\ % etc & lib32 & nrc & srv & var & \\ % fotos & lib64 & opt & store & vmlinuz & \\
synopsis: | handle_options "$@" |
description: | handle the options. |
globals used: | Myname Version |
globals set: | args squeeze across sep pre suf cols |
returns: | the number of remaning arguments |