-1

I have users like below in many *sh scripts.

test1@gmail.com
user@ymail.com
test2@gmail.com

I want to replace any emails like above with admin@yahoo.com in linux.

Any idea will be appreciated ?

3

To replace the part before @ (I think that's what you want), you could use:

sed 's/[^ ]\+@/admin@/g' file
  • s/old/new/ replace old with new
  • [^ ]\+@ match at least one non-whitespace character followed by @
  • g do the replacement on all matches, even if it occurs more than once on the line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.