Skip to content

Instantly share code, notes, and snippets.

@fabiolimace
Created May 2, 2026 03:47
Show Gist options
  • Select an option

  • Save fabiolimace/458400e41eb4acc4834d3a49e7836a9a to your computer and use it in GitHub Desktop.

Select an option

Save fabiolimace/458400e41eb4acc4834d3a49e7836a9a to your computer and use it in GitHub Desktop.
List suffixes
#!/usr/bin/awk -f
#
# time ./list-suffixes.awk < /usr/share/dict/portuguese
#
function load(dict) {
while ( (getline word < dict) > 0 ) {
DICT[i++] = word
}
SIZE=length(DICT);
close(dict);
}
function find(word) {
for ( w = 1 ; w <= SIZE ; w++ )
{
if ( word == DICT[w] )
{
return i;
}
}
return 0;
}
BEGIN {
load("/usr/share/dict/portuguese");
}
# print suffixes of selected samples
(length >= 10) && (x++ % 10 == 0) {
for ( i = length()-6 ; i < length() ; i++)
{
root = substr($0, 1, i);
if (find(root)) {
suff = substr($0, i + 1);
print (suff, $0);
next;
}
}
}
END {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment