Replace with sed

Sometimes I use an Apache template where some values are parameterized like:

<VirtualHost *:80>
    ServerName <SERVER_NAME> 
    	DocumentRoot <DOCUMENT_ROOT>
        ...	
</VirtualHost>

And I use a bash script to change this parameters:

DOMAIN='razvantudorica.com'
WEB='/var/www/razvantudorica'
sed -i "s/<SERVER_NAME>/$DOMAIN/g" /etc/apache2/sites-enabled/razvantudorica.conf

But, if the variable contains a slash (/) it will not work and I use this syntax:

sed -i "s,<DOCUMENT_ROOT>,$WEB,g" /etc/apache2/sites-enabled/razvantudorica.conf

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.