开发者

How can I replace all hotmail.com addresses in a file with another email address, using Perl?

I have multiple email id's in some config files in a directory; I'm running my scripts on a Solaris machine. I want to perform the following:

Find all the email_id's in the config files in a directory: eg: abcd@hotmail.com ; dfgh@hotmail.com ; mnop@hotmail.com ; fghk@hotmail.com

Replace all existing id's with: wxyz@hotmail.com

The following implementation can help me replace "hotmail" with "gmail" for all the开发者_高级运维 email id's in the config files. But i'm a little confused to solve the above problem

perl -pi -e 's/\@hotmail/\@gmail/g' *

Thanks in advance!


Try

's/\S+@hotmail\.com/wxyz@hotmail.com/g'


What you need is an editor with regex/global replace (and make sure it creates *.bak files)

sure, coding this is fun ..


using the solution posted by heferav, i don't seem to get the answer

$ more file
abcd@hotmail.com ; dfgh@hotmail.com ; mnop@hotmail.com ; fghk@hotmail.com
$ perl -ne 'print if s/\S+@hotmail\.com/wxyz@hotmail.com/g' file
wxyz.com ; wxyz.com ; wxyz.com ; wxyz.com

maybe I am missing something. @OP, since you are working in Solaris, i assume you can use nawk

$ nawk '{ for(i=1;i<=NF;i++){gsub(/.*@hotmail.com/,"wxyz@hotmail",$i)} }1' file
wxyz@hotmail ; wxyz@hotmail ; wxyz@hotmail ; wxyz@hotmail
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜