gawk -F, 'BEGIN {FS=","; OFS="," Enough=1; } function str(n,c, s) { while(n--) s = s c; return s } function round(x) { return int(x + 0.5) } function chop(s) { gsub(/^[ \t]*/,"",s); gsub(/[ \t]*$/,"",s); return s} /^[ \t]*1/ { next } { sub(/#.*/,"") } /^[ \t]*$/ { next } { for(I=1;I<=NF;I++) $I=chop($I) } Pass==1 { Name[$1]=$2 } Pass==2 { Total += $NF } Pass==3 { Report = round(100*$NF/Total) if (Report >= Enough) { print sprintf(",%5.0f",Report) OFS "\\rule{"Report"mm}{1mm}" OFS $1 OFS Name[$1] OFS } } ' Pass=1 names.csv Pass=2 $1 Pass=3 $1 | malign | sort -t, -n -r +0 -n +1