Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Golfing =)</p> <pre><code>$ cat FILE Example, peter@yahoo.com peter@hotmail.co.in philip@gmail.com $ sed -r 's!@(.*)!_\1@generic.com!' FILE Example, peter_yahoo.com@generic.com peter_hotmail.co.in@generic.com philip_gmail.com@generic.com </code></pre> <p>In reply to user1428900, this is some explanations :</p> <pre><code>sed -r # sed in extended regex mode s # substitution ! # my delimiter, pick up anything you want instead !part of regex @(.*) # a literal "@" + capture of the rest of the line ! # middle delimiter _\1@generic.com # an "_" + the captured group N°1 + "@generic.com" ! # end delimiter FILE # file-name </code></pre> <p>Extended mode isn't really needed there, consider the same following snippet in <code>BRE</code> (basic regex) mode :</p> <pre><code> sed 's!@\(.*\)!_\1@generic.com!' FILE </code></pre> <p><strong>Edit</strong> to fit your new needs :</p> <pre><code>$ cat FILE Example, peter@yahoo.com,I am peter peter@hotmail.co.in philip@gmail.com $ sed -r 's!@(.*),.*!_\1@generic.com!' FILE Example, peter_yahoo.com@generic.com peter@hotmail.co.in philip@gmail.com </code></pre> <p>If you want only email lines, you can do something like that :</p> <pre><code>sed -r '/@/s!@(.*),.*!_\1@generic.com!' FILE </code></pre> <p>the <code>/@/</code> part means to only works on the lines containing the character <code>@</code></p> <p><strong>Edit2</strong>:</p> <p>if you want to keep the end lines like your new comments said :</p> <pre><code>sed -r 's!@(.*)(,.*)!_\1@generic.com\2!' FILE </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload