Created
May 2, 2026 03:47
-
-
Save fabiolimace/458400e41eb4acc4834d3a49e7836a9a to your computer and use it in GitHub Desktop.
List suffixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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