I'm looking for a way to replace all e-mail addresses in a file with [email protected] I guess sed is the right tool for the job, but I'm unable to find the way to do it in a robust and correct way. Thanks.
Here is one crude way of doing that using sed -r
:
sed -r 's/^(.*? |)[^@]+@[^ ]+/\[email protected]/g' file
On BSD (eg OSX) use this variant:
sed -E 's/(^|.* )[^@]+@[^ ]+/\[email protected]/g' file
Though keep in mind email addresses can vary a lot these days.
The following worked for me:
sed "s/[^@ ]*@[^@]*\.[^@ ]*/[email protected]/g" file
applied on the following file
[email protected] has an address
so has [email protected]
and finally [email protected] and other stuff
The command C:\Temp>d:sed "s/[^@ ]*@[^@]*\.[^@ ]*/[email protected]/g" file
gets me this:
[email protected] has an address
so has [email protected]
and finally [email protected] and other stuff
This obfuscates email-adresses partially:
sed -E 's/[a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_]@[a-zA-Z0-9_][a-zA-Z0-9_]/xxxx@xx/g'
I found this easier to develop with. Automated tests can now test for specific email adresses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With