2

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?

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412

2 Answers2

1

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"
Steve
  • 51,466
  • 13
  • 89
  • 103
  • I updated my question. I need to remove the entire email address if it matches `@mydomain.edu` – Nic Hubbard Aug 09 '12 at 23:29
  • @NicHubbard: I think I edited that just before/after you accepted. This version will be more robust for you. Glad I could help :-) – Steve Aug 09 '12 at 23:55
0

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.

Johnnywho
  • 5,541
  • 2
  • 27
  • 20