0

IT seems that 'sed' and I will never be friends...

How can I find and replace a pattern within a range (within another pattern)?

In words: Find: AllowOverride None within the following range and replace it with AllowOverride All

...
<Directory "/var/www/html">
some text
more text
some comments
AllowOverride None
more text
</Directory>
...

Please note (if not already done): This is related to httpd.conf which contains a lot more "modules" all ending with </Directory>

As this command is used within a yaml file, it would be aesome to achieve this with a one-liner (I am aware, that one-liners are getting ugly pretty fast...).

Also: I rely on using sed (requirement, dont ask me why - pls :))

1 Answer 1

2

With GNU sed:

sed -i -e '/<Directory "\/var\/www\/html">/,/<\/Directory>/{s/AllowOverride None/AllowOverride All/}' filename
1
  • It makes so much sense looking at it now. Thank you!
    – frank
    Commented Apr 5, 2015 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .