Extended experiment with command line dictionary

After my old experiments with dictionary server protocol linux rfc 2229 i just wanted to try getting a mammoth list of synonyms for list of any give list, let logic behind it was pretty simple, but the pleasure that it gave was ultimate.

First off we need to install dict DICT Protocol Client. For a Debian based OS, its just sudo apt-get install dict.[ Read more ]

Now lets see the similar one liner that will make the magic happen, it's just a simple cocktail of dict and awk

Here are the ingredients :
0. dict.
1. A list of words. [ Its called wordList here ]
2. awk.
After baking we get another big list of synonyms, for each word in the list

Code
for word in $(cat wordList);  
do dict $word | \
awk 'BEGIN {Word=$word} /Word/,0' \
>> synonyms; 
done

Dismantling the code:

The loop and the dict command are straight forward, the only nut for us to crack is the awk part of the code.

It begins with a defining a variable called Word, which is each word looped at a time from the wordList file.

Next, we see the /Word/,0 which is nothing but the awk built-in support for range expressions prints lines from /beginpat/ to /endpat/, inclusive here every pattern matching the "Word" in the output of the dict command is matched and is redirected (>) to a file called "synonyms".

Thus we end up with the fully baked file ready to eat, enjoy and do share your recipes here.

Share this