How to replace a string containing @ in a file using sed ?

I have a list of names and email addresses.
Sample File -

username=poga--poga@yahoo.com
new-york,US
512834
username=poga123--poga123@hotmail.com
new-jersey,US
0894753

Requirement is to replace the email ids as dummy_username@xyz.com using sed only.
Output File -

username=poga--dummy_poga@xyz.com
new-york,US
512834
username=poga123--dummy_poga123@xyz.com
new-jersey,US
0894753

[/COLOR][/i]Please help. I am using sed but it seems that the "@" is creating the problem
Thanking in advance,
Poga

 sed 's/\([^-@]*@\)/dummy_\1/'

seems to work for me

Why must it be sed? And what have you tried so far?

Thanks everybody. resolved it. I had forgotten to escape the "@" and "."

sed "s/$EMAIL/dummy_$username\@xyz\.com/g" filename.txt

The @ didn't need escaping but the dots did. :slight_smile:

2 Likes