How to make sed anonymize all email addresses in a file

I'm looking for a way to replace all the email addresses in a file with xxx@xxx.xxx I think sed is the right tool to work, but I can't find a way to do this in a reliable and proper way. Thank you

+4
source share
2 answers

Here is one rough way to do this using sed -r :

 sed -r 's/^(.*? |)[^@] +@ [^ ]+/\ 1xxx@xxx.xxx /g' file 

In BSD (e.g. OSX) use this option:

 sed -E 's/(^|.* )[^@] +@ [^ ]+/\ 1xxx@xxx.xxx /g' file 

Keep in mind though that these days email addresses can vary greatly.

+2
source

The following worked for me:

 sed "s/[^@ ]*@[^@]*\.[^@ ]*/ xxx@xxx.xx /g" file 

applies to the following file

 charly.chaplin@web.de has an address so has axel.springer@bild.de and finally henry@kissinger.info and other stuff 

The command C:\Temp>d:sed "s/[^@ ]*@[^@]*\.[^@ ]*/ xxx@xxx.xx /g" file gets me this:

 xxx@xxx.xx has an address so has xxx@xxx.xx and finally xxx@xxx.xx and other stuff 
+1
source

Source: https://habr.com/ru/post/1498176/


All Articles