smushi
smushi

Reputation: 719

replace all instance of email addresses with "@example.com"

(another question, sorry but stressing for exam).

I have a file I am going to read in from STDIN. It has text and bunch of emails in the text.

"blah blah blah something [email protected] blah blah [email protected]".

i want to replace all email addresses domain name with "@example.com". So the above becomes

"blah blah blah something [email protected] blah blah [email protected]"

Here is the code i have so far.

#!/usr/bin/perl

while($line = <STDIN>){
  $line =~ s/'@'+'.com'\s/"@example.com"/g;

  print $line;
 }

Upvotes: 0

Views: 110

Answers (1)

Miller
Miller

Reputation: 35208

$line =~ s/(\S+)@\S+/$1\@example.com/g;

Upvotes: 2

Related Questions