I am working on building a .sed file to start scripting the setup of multiple apache servers. I am trying to get sed to match the default webmaster email addresses in the .conf file which works great with this egrep. However when I use sed to try and so a substitute search and replace i get no errors back but it also does not do any substituting. I test this by running the same egrep command again.
egrep -o '\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+(\.[A-Za-z]{2,4})?\b' /home/test/httpd.conf
returns
admin@your-domain.com
root@localhost
webmaster@dummy-host.example.com
The sed command I’m trying to use is
sed -i '/ServerAdmin/ s/\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+(\.[A-Za-z]{2,4})?\b/MY_ADMIN_ADDRESS@gmail.com/g' /home/test/httpd.conf
After running I try and verify the results by running the egrep again and it returns the same 3 email address indicating nothing was replaced.
sed must be told that it needs to use extended regular expressions using the -r option then making the sed command as follows.
Much thanks to Kent for pointing out that the address it was missing wasnt following a
ServerName