//View Tip #525
Similar Tips
» Find function declarations in PHP or JavaScript
» BBC Weather
» Get real names of current users
» List non-system users
» Get latest stable version of the Linux kernel

 

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

Comments are currently disabled
No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit