PDA

View Full Version : Email and Grep


TreasonX
17th October 2005, 12:58 AM
I recently had to pull a bunch of email addresses from a txt file with a bunch of mixed lines of text. Im really new to grep so it took me sometime and I finally got it to work almost perfect. It spit out the name and email address when ever it found an @ symbol. I was just wondering is there a better way to do this and am I on the right track?

Here is an example of the text file lines.. The have been edited to protect the innocent:


> Tom ( tom@blahblah.org ntohing),
>
> Julie yyum (jblizzzab@comcast.net, jull_assn@post.smoeschool.edu, but
> doesn't check email regularly; I have her phone number if necessary),
>
> Julia (julia@rabloappoosen.org , lj=stawelcomester),
>
> Jim ( mooper@aol.net, lj=mmmooyyeqt) and Honey
> ( honey@raverscene.net, honeyb@rigo.film.org, honeyb@film.org ,
> lj=lfunnybutone),


Here is the grep that I came up with:



[James@treasonx ~]$ grep -o '[a-Z].*@*.com\b' email.txt > address_com.txt
[James@treasonx ~]$ grep -o '[a-Z].*@*.org\b' email.txt > address_org.txt
[James@treasonx ~]$ grep -o '[a-Z].*@*.edu\b' email.txt > address_edu.txt
[James@treasonx ~]$ grep -o '[a-Z].*@*.net\b' email.txt > address_net.txt
[James@treasonx ~]$ grep -o '[a-Z].*@*.gov\b' email.txt > address_gov.txt



And here is the output I got well an example of what it looked like:



Mike (mikers@alumni.mit.edu
Julie (jukilfunab@comcast.net
Jim ( jnoobes@myplace.net
honey@raverscene.net



It took me about 15 minutes to get this to work.. Is this the easiest way or did I kill myself doing it this way? Also I would have liked to just get the email addresses but getting the names before them was an added bonus. How could I have just gotten the email address?

Jman
17th October 2005, 06:23 AM
I don't know, I need to learn more regular expressions.

But here's a tool (http://tools.perceptus.ca/text-wiz.php?ops=5) that should extract email addresses.

TreasonX
17th October 2005, 02:24 PM

Thats exactly what I wanted.. Now how did they do that :)