Monday, December 5, 2011

Get one word (or phrase) only from a set of text or file

So  you want to get some text from a file.  Easy, use grep.  What; you want more than that?  Oh, you want ONLY the word (or phrase) from that file, not the entire line!  Ahhh!

It took me a few tries, but I combined grep and sed to give me the line I wanted, then then only the word I wanted.

In this case I was searching spam emails I have gotten for the senders email address. 


grep -i "From: " *|  sed -e 's/^.*<\(.*\)>,*/\1/'

The line from the grep looks like:
3 0735.eml:From: "Fraud Prevention" <douchbag@spamsucks.com>

Then the sed line pulls out the email between the < >

No comments:

Post a Comment