Wednesday, 15 June 2011

SED command matches regex but does not substitute -



SED command matches regex but does not substitute -

i working on building .sed file start scripting setup of multiple apache servers. trying sed match default webmaster email addresses in .conf file works great egrep. when utilize sed seek , substitute search , replace no errors not substituting. test running 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 utilize

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 seek , verify results running egrep 1 time again , returns same 3 email address indicating nil replaced.

don't assume 2 tools utilize same regular look syntax. if you're going doing replacements sed, utilize sed test - not egrep. it's easy utilize sed if grep command: sed -ne '/pattern/p'.

regex sed grep

No comments:

Post a Comment