awkcol.sh (602B)
1 #!/usr/bin/env sh 2 # columnate with awk 3 # description: sometimes you reach the limit of 'column' 4 # dependencies: awk 5 # e.g.$ mount | awkcol 6 # source: http://awk.freeshell.org/Columnate 7 awk '{ 8 line[NR] = $0 # saves the line 9 for (f=1; f<=NF; f++) { 10 len = length($f) 11 if (len>max[f]) 12 max[f] = len # an array of maximum field widths 13 } 14 } 15 16 END { 17 for(nr=1; nr<=NR; nr++) { 18 nf = split(line[nr], fields) 19 for (f=1; f<nf; f++) 20 printf "%-*s", max[f]+2, fields[f] 21 print fields[f] # the last field need not be padded 22 } 23 }' 24