Mike Sanders
2023-10-11 00:51:07 UTC
# Michael Sanders 2023
# https://busybox.neocities.org/notes/isogram.txt
#
# awk script that displays isograms using inverse ANSI
# escapes (meaning fore & background colors are swapped)
# requires an ANSI capable terminal, rename this file
# and invoke script as:
#
# awk -f isogram.awk 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)
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
}
{
word = ""
line = ""
for (x = 1; x <= length($0); x++) {
c = substr($0, x, 1)
if (c ~ /[[:space:]]/ || x == length($0)) {
if (x == length($0) && 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
# https://busybox.neocities.org/notes/isogram.txt
#
# awk script that displays isograms using inverse ANSI
# escapes (meaning fore & background colors are swapped)
# requires an ANSI capable terminal, rename this file
# and invoke script as:
#
# awk -f isogram.awk 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)
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
}
{
word = ""
line = ""
for (x = 1; x <= length($0); x++) {
c = substr($0, x, 1)
if (c ~ /[[:space:]]/ || x == length($0)) {
if (x == length($0) && 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
--
:wq
Mike Sanders
:wq
Mike Sanders