#! /usr/bin/gawk -f # Last edited on 2004-02-07 04:30:29 by stolfi BEGIN { # Counts characters. Ignores leading, trailing, and redundant blanks. # Ignores #-comments and {}-comments. Newlines are counted too. split("", ct); } /^[ ]*([\#@]|$)/ { next; } /./ { lin = $0; # Replace inlined @{}{}-constructs by their text content: lin = gensub(/[@][{][^{}]*[}][{]([^{}]*)[}]/, "\\1", "g", lin); # Remove {}-comments: gsub(/[{][^{}]*[}]/, "", lin); # Remove redundant spaces. gsub(/^[ ]+/, "", lin); gsub(/[ ]+$/, "", lin); gsub(/[ ][ ]+/, " ", lin); # Count characters in {lin}: n = length(lin); for (i = 1; i <= n; i++) { c = substr(lin, i, 1); ct[c]++; } ct["NL"]++; next } END { for(c in ct) { printf "%7d %s\n", ct[c], (c == " " ? "SP" : c); } }