Question

I am using textwrangler and am new to regex. I have a bunch of emails addresses, but I need to remove only those that are @mydomain.edu addresses.

Standard Hall,414,Ashley,Smith,"asmith@mydomain.edu, asmith@otherdomain.com"
Standard Hall,414,Stacy,Smith,"ssmith@mydomain.edu, ssmith@otherdomain.com"

As you can see, each line has an email address that uses @mydoamin.com. I would like to remove the entire email address every time @mydomain.com occurs, and leave the alternate email.

Is there a way to do this?

Était-ce utile?

La solution

If your addresses are in a list one per line, you could use grep:

grep -v "@mydomain.edu" file.txt

EDIT awk:

awk -F, '$5 ~ /@mydomain.edu/ { sub("[^\", ]*@mydomain.edu[, ]*","") }1' file.txt

Results:

Standard Hall,414,Ashley,Smith,"asmith@otherdomain.com"
Standard Hall,414,Stacy,Smith,"ssmith@otherdomain.com"

Autres conseils

In TextWrangler's Find mark the Grep checkbox and insert this line in Find textbox:

([a-zA-Z0-9\.]*@mydomain.edu(, )?)|((, )?[a-zA-Z0-9\.]*@mydomain.edu)

Then hit Replace All. This will remove all emails with that domain and leave correct number of commas.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top