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 ( email@example.com ntohing),
> Julie yyum (firstname.lastname@example.org, email@example.com, but
> doesn't check email regularly; I have her phone number if necessary),
> Julia (firstname.lastname@example.org , lj=stawelcomester),
> Jim ( email@example.com, lj=mmmooyyeqt) and Honey
> ( firstname.lastname@example.org, email@example.com, firstname.lastname@example.org ,
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:
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?