Q1:
I would like to edit a file containing a set of email ids such that all the domain names become generic.
Example,
peter@yahoo.com
peter@hotmail.co.in
philip@gmail.com
to
peter_yahoo@generic.com
peter_hotmail@generic.com
philip_gmail@generic.com
I used the following sed cmd to replace @ with _
sed 's/@/_/' <filename>
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?
Q2:
so how do I approach this if I had text at the end of my domain names?
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
I tried @(,) instead of @(.*)
it doesn’t work and I cant think of any other solution
Q3:
Suppose if my example is like this,
peter@yahoo.com
peter@hotmail.co.in,i am peter
I want my result to be as follows,
peter_yahoo.com@generic.com
peter_hotmail.co.in@generic.com,i am peter,i am peter
How do i do this with a single sed cmd?
The following cmd would result in,
sed -r 's!@(.*)!_\1@generic.com!' FILE
peter_yahoo.com@generic.com
peter_hotmail.co.in,i am peter,i am peter@generic.com
And the following cmd wont work on “peter@yahoo.com”,
sed -r 's!@(.*)(,.*)!_\1@generic.com!' FILE
Thanks!!
Golfing =)
In reply to user1428900, this is some explanations :
Extended mode isn’t really needed there, consider the same following snippet in
BRE(basic regex) mode :Edit to fit your new needs :
If you want only email lines, you can do something like that :
the
/@/part means to only works on the lines containing the character@Edit2:
if you want to keep the end lines like your new comments said :