I need to get a list of all the email addresses from a file.
I was trying to use
grep @ filename
but that returns the entire line.
Is there anyway I can get it to return only the email address and not the whole line?
@rbright this solution seems to work. the "-o" option is what I was missing! But I ended up just writing a php script before I got your response.
$handle = fopen("MYFILE.txt","r");
This is a fast and dirty but it will hold up until there is a @ that is not in a email address which is very unlikely in my situation
Note that properly matching any valid email address is a deep magic, so if you really want to catch everything with no false positives or negatives, you should use a regex someone else has written. But if you're just looking for a quick
That will catch some simple email addresses, along with some things that are not valid email addresses (like "@@@@.a"). Adjust your regex as appropriate. E.g., this one is more restrictive:
That's going to depend on the format of the file. For example, let's say the file has
email@example.com stuff you don't want firstname.lastname@example.org more stuff you don't want email@example.com and more
Post an example of the file format if that's not what you've got.