# # Rewrite a rectangular file so each field formatted to same length # if [ "$1" = "-h" ] || [ "$1" = "--help" ] then echo "bester " echo "Reformat a file so that each column" echo "is of constant width (that of widest word in that column)." exit fi AWK=/bin/gawk $AWK ' BEGIN { fld=0 } { print } NF>1 && substr($1,1,1) !~ "[!#]" { if (NF>fld) fld=NF for(i=1;i<=NF;i++) { len=length($i) if (maxlen[i] "best.awk" printf "substr($1,1,1) ~ \"[!#]\" { print $0 }\n" >> "best.awk" printf "substr($1,1,1)!~ \"[!#]\" { \n printf \"" >> "best.awk" for (i=1;i<=fld;i++){ printf "%s%s%s ","%-",maxlen[i],"s" >> "best.awk" } printf "\\n\", \\\n $1" >> "best.awk" for (i=2;i<=fld;i++){ printf ", $%s",i >> "best.awk" if (i%12==0) {printf " \\\n " >> "best.awk"} } printf "\n}" >> "best.awk" }' $* > bester$$ awk -f best.awk bester$$ rm bester$$ best.awk