#! /usr/bin/gawk -f # Last edited on 2026-03-11 01:11:48 by stolfi # Reads an ".opa" file from {stdin}. Writes to {stdout} a summary with # the count of lines where the pattern occurs at position {p}, # for each {p}. BEGIN { split("", nline); split("", npara); pmax = -1; sfmt=" %6s %4s %4s %5s\n" nfmt=" %6s %4d %4d %5.1f\n" printf sfmt, "pos", "nlin", "npar", "%par" printf sfmt, "------", "----", "----", "-----" } /^[a-z]/{ loc = $1; p = $2+0; pref = $3; key = $4; suff = $5; text = $6 if (p == 0) { print > "/dev/stderr" } while (pmax < p) { pmax++; nline[pmax] = 0; npara[pmax] = 0; } nline[p] += 1; if (match(text, /<%>/)) { npara[p] += 1; } } END { p0 = 0; tline = 0; tpara = 0 while (p0 < pmax) { p1 = (p0 < 10 ? p0 : p0 + 9) sline = 0; spara = 0 for (p = p0; p <= p1; p++) { sline += nline[p]; spara += npara[p]; } xp = (p0 < p1 ? sprintf("%d..%d", p0 ,p1) : sprintf("%d", p0) ) spct = (sline == 0 ? 0 : 100*spara/sline) printf nfmt, xp, sline, spara, spct tline += sline; tpara += spara p0 = p1 + 1 } tpct = 100*tpara/tline printf nfmt, "TOTAL", tline, tpara, tpct }