# tags: isogram, awk, ANSI, code # # Michael Sanders 2023 # https://busybox.neocities.org/notes/isogram.txt # # last revision: 2023.10.12 # # awk script that displays isograms using inverse ANSI # escapes (meaning fore & background colors are swapped) # requires an ANSI capable terminal, invoke script as: # # awk -f isogram.txt file # # isogram test block... # # aberration lucrative concurrent espouse obfuscate # garrulous promenade epiphany requiem juxtapose # languid ephemeral abscond extricate circumvent # obstinate vivacious corroborate attenuate paragon # penchant serendipity superfluous immutable mitigate # aplomb concatenate ethereal diaphanous demagogue # cogitate pervasive anathema juxtaposition memento # disparate oscillate ennui perfunctory parabola # mellifluous recumbent ephemeral sycophant timorous # voracious quixotic serenade conundrum vicarious # insipid ornate camaraderie cogent introspection # sanguine deleterious impeccable extraneous loquacious BEGIN { print "\nisograms...\n" } function hilite(str) { return "\033[7m" str "\033[0m" } function isogram(str, c, x, y) { y = length(str) if (y < 2) return 0 # !isogram for (x = 1; x <= y; x++) { c = substr(str, x, 1) if (index(substr(str, x + 1), c) > 0) return 0 # !isogram } return 1 # isogram } { line = word = "" y = length($0) for (x = 1; x <= y; x++) { c = substr($0, x, 1) if (c ~ /[[:space:]]/ || x == y) { if (x == y && c !~ /[[:space:]]/) word = word c line = (isogram(word) ? line hilite(word) : line word) if(c ~ /[[:space:]]/) line = line c word = "" } else { word = word c } } print line } # eof