3

Tip #525   Find words in garbled text

Have a bunch of garbled text? Curious as to what words might be found inside? Try the following:

echo "Garbled Text" | grep -o -F -f /usr/share/dict/words | sed -e "/^.$/d"


Breakdown:

The grep -o -F -f /usr/share/dict/words takes whatever xclip told it and finds all the words. -F means "I'm going to tell you a list of patterns to match against, not just one." -f means "Not just a normal pattern, but everything inside this file." /usr/share/dict/words is the system dictionary. -o means "Just tell me what you found, not the entire thing."

sed -e "/^.$/d" means "Get rid of every word that's a single letter long.

For example:

echo asjdpastaxrdsdtasteifcoinade | grep -o -F -f /usr/share/dict/words | sed -e "/^.$/d"

Gives the following list of words: as, pasta, taste, if, coin, ad

For a more complicated version, this can be combined with xclip to work with the clipboard. The following command will find words in the text currently copied and place a comma separated list of words back in the clipboard.
(for i in `xclip -o -selection clipboard | grep -o -F -f /usr/share/dict/words | \
sed -e "/^.$/d"`; do echo -n "$i, "; done) | tee >(xclip -selection clip)