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)
- TAGS:
- grep
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs