title: How to replace all email addresses in a set of files with a generic email address
body: <p>I have some scripts which have many email address in different domain (say <code>domain1.com</code>,<code>domain2.com</code> . I want to replace all of them with some generic email address in a common domain, say <code>domain.com</code>, keeping rest of the script same.</p>
  
  <p>I am using below in <code>sed</code> but it doesn't seem to work. (it is returning same output as input, so looks like the search is not matching. However, when I tested the regex <code>\S+@\S+/</code> in online tester, it seems to match email addresses.)</p>
  
  <blockquote>
    <p><code>s/\S+@\S+/genericid@domain.com/g</code></p>
  </blockquote>
  
  <p>For example, I have 2 scripts</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>My result after <code>sed -i</code> should be</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>I am using <code>Linux 3.10.0-327.28.2.el7.x86_64</code></p>
  
  <p>Any suggestion please?</p>
  
  <p>Update: 
  I managed to make it work with <code>'s/\S\+@\S\+.com/genericid@domain.com/g'</code>. There were 2 problem with previous <code>search</code>.</p>
  
  <ul>
  <li>The <code>+</code> needed <code>\</code> before it. </li>
  <li>As file had other <code>@</code> lines (for
  database connections), I had to append <code>.com</code> at the end, as all my
  addresses ended in <code>.com</code></li>
  </ul>