How to replace all email addresses in a file set with a shared email address

I have several scripts that have many email addresses in different domains (say domain1.com, domain2.com). I want to replace all of them with a single shared email address in a shared domain, say domain.comleaving a script.

I use below in sed, but it does not work. (It returns the same output as the input, so it looks like the search does not match. However, when I tested the regular expression \S+@\S+/in the online test, it seemed to match the email addresses.)

s/\S+@\S+/genericid@domain.com/g

For example, I have 2 scripts

$ cat script1.sh
abcd.efg@domain.com
export SENDFROM="xyz@domain1.com" blah_4

$ cat script2.sh
echo foo|mailx -s "blah" pqr@domain2.com,def@domain.com,some@domain.com
 omg@domain.com
foo abc@domain.com bar

My result after sed -ishould be

$ cat script1.sh
genericid@domain.com
export SENDFROM="genericid@domain.com" blah_4

$ cat script2.sh
echo foo|mailx -s "blah" genericid@domain.com,genericid@domain.com,genericid@domain.com
 genericid@domain.com
foo genericid@domain.com bar

I use Linux 3.10.0-327.28.2.el7.x86_64

Any suggestion please?

: 's/\S\+@\S\+.com/genericid@domain.com/g'. search.

  • + \ .
  • @ ( ), .com , .com
+4
3

. , , , ; perl, , , . , , .

-

( ), , , .

, , \S -, address@something.com,address@somethingelse.com, , .

, , , . \S [^\s,] ( s), , , .

+1

, . , , , , , :

1 alphanum char + @ + N alphanum chars + . + N alphanum chars

, javascript :

(\ @) (\ *.\ *)

$1newdomain.com

, .

+2

sed s/[^,@]*@[^,]*/genericid@domain.com/g

echo 'pqr@domain2.com,def@domain.com,some@domain.com' | sed s/[^,@]*@[^,]*/genericid@domain.com/g

genericid@domain.com,genericid@domain.com,genericid@domain.com
0

Source: https://habr.com/ru/post/1660789/


All Articles