Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to apply two different sed commands on a line?
    text
    copied!<p>Q1: I would like to edit a file containing a set of email ids such that all the domain names become generic.</p> <pre><code>Example, peter@yahoo.com peter@hotmail.co.in philip@gmail.com to peter_yahoo@generic.com peter_hotmail@generic.com philip_gmail@generic.com </code></pre> <p>I used the following sed cmd to replace @ with _</p> <pre><code>sed 's/@/_/' &lt;filename&gt; </code></pre> <p>Is there a way to append another sed cmd to the cmd mentioned above such that I can replace the last part of the domain names with @generic.com?</p> <p>Q2: so how do I approach this if I had text at the end of my domain names?</p> <pre><code>Example, peter@yahoo.com,i am peter peter@hotmail.co.in,i am also peter To, peter_yahoo.com@generic.com,i am peter peter_hotmail.co.in@generic.com,i am also peter </code></pre> <p>I tried @(,) instead of @(.*) it doesn't work and I cant think of any other solution</p> <p>Q3: Suppose if my example is like this,</p> <pre><code>peter@yahoo.com peter@hotmail.co.in,i am peter </code></pre> <p>I want my result to be as follows,</p> <pre><code>peter_yahoo.com@generic.com peter_hotmail.co.in@generic.com,i am peter,i am peter </code></pre> <p>How do i do this with a single sed cmd?</p> <p>The following cmd would result in,</p> <pre><code>sed -r 's!@(.*)!_\1@generic.com!' FILE peter_yahoo.com@generic.com peter_hotmail.co.in,i am peter,i am peter@generic.com </code></pre> <p>And the following cmd wont work on "peter@yahoo.com",</p> <pre><code>sed -r 's!@(.*)(,.*)!_\1@generic.com!' FILE </code></pre> <p>Thanks!!</p>
 

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