I am trying to automate the provisioning of an Ubuntu Vagrant box with a Bash script. All is well, but I am having difficulty with configuring Apache to allow overrides from .htaccess
files. In my config file, there is the following block:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
All I need to do is replace AllowOverride None
with AllowOverride all
. This seems to be a task for sed
, but there are other <Directory>
blocks in this config file where I do not want to allow override.
How can I use sed to replace a specific string with a new string, when that specific string occurs between two other specific strings?
In other words, how can I replace AllowOverride None
only when it appears between <Directory /var/www/>
and </Directory>
?
I can use the following command to get the block I am interested in:
sed -n '/<Directory \/var\/www\/>/,/<\/Directory>/p' 000-default
Best Answer
sed
supports pattern ranges in this form:For example: