//View Tip #525
Similar Tips
» Random xkcd comic
» Print a random shell-fu tip
» Get your IP in one line
» Find occurrences of a string in a large code base without firing
» Find and Grep

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
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)


View Comments »



Comments 

Add your comment

CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.

No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit