Although command column might not be on some UNIX boxes, I'd rather have a limited general facility like column, rather than a plethora of single-shot solutions for lots of similar, but different situations.
The perl module Array::columnize allows one to create a work-alike. We use one such for the cases when column might not exist on a platform, like so:
#!/usr/bin/env bash
# @(#) s1 Demonstrate columnize with standard GNU/Linux column, local my-columns.
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
edges() { local _f _n _l;: ${1?"edges: need file"}; _f=$1;_l=$(wc -l $_f);
head -${_n:=3} $_f ; pe "--- ( $_l: lines total )" ; tail -$_n $_f ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C column my-columns divepm
FILE=${1-data1}
pl " Input data file $FILE:"
cat $FILE
pl " Results, standard Linux column:"
column -c60 $FILE
pl " Results, work-alike for Linux column, \"my-columns\":"
my-columns -w 60 $FILE
pl " Characteristics of my-columns:"
v1=$( command -v my-columns )
file "$v1" | sed 's/^.*: //'
pe "Lines: $( wc -l < $( command -v my-columns ) )"
pe "Modules used by my-columns:"
divepm -q -i $v1
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
column - ( /usr/bin/column, 2007-11-20 )
my-columns (local) 1.2
divepm (local) 1.2
-----
Input data file data1:
apples
oranges
cats
dogs
sky
monkey
giraffe
cups
spoons
tv
cable
-----
Results, standard Linux column:
apples cats sky giraffe spoons cable
oranges dogs monkey cups tv
-----
Results, work-alike for Linux column, "my-columns":
apples cats sky giraffe spoons cable
oranges dogs monkey cups tv
-----
Characteristics of my-columns:
a perl script text executable
Lines: 67
Modules used by my-columns:
1.06 warnings
1.04 strict
1.04 English
1.08 Carp
2.37 Getopt::Long
0.4.2 Array::Columnize
1.11 feature