#! /usr/bin/gawk -f # Usage: $0 -v MAX1=nnn -v MAX2=nnn -v MAX3=nnn < INFILE > OUTFILE # Reads a list of records in the format # PAGENUM PAGENAME ABS1 REL1 ABS2 REL2 ABS3 REL3 # where PAGENUM is a numeric page index, PAGENAME is a # folio/panel page identifier (as f101v2), the ABSi are # absolute counts, and the RELi are relative counts. # # Prints that data in the format # PAGENUM PAGENAME ABS1 REL1 HIST1 ABS2 REL2 HIST2 ABS3 REL3 HIST3 # where each HISTi is a "bar" representation of RELi: a string # of nine "o"s and "."s, where nine "o"s represent RELi = MAXi. function error(msg) { printf "%s\n", msg > "/dev/stderr" abort = 1 } function bar(val, max, n) { if (val > max) { error(("val = " val " over max = " max)); exit 1 } n = int((9*val)/max) return (substr("ooooooooo",1,n) substr(".........",1,9-n)) } BEGIN { abort = 0 if (MAX1 == "") { error("MAX1 not defined"); exit 1 } if (MAX2 == "") { error("MAX2 not defined"); exit 1 } if (MAX3 == "") { error("MAX3 not defined"); exit 1 } } /./ { if (abort) exit 1; printf \ "%03d %-6s %5d %5d %-9s %5d %5d %-9s %5d %5d %-9s\n", \ $1, $2, $3, $4, bar($4, MAX1), $5, $6, bar($6, MAX2), $7, $8, bar($8, MAX3) next }