I'm trying to script a change to my apache config file (httpd.conf). I'm trying to match the following string:

```
#
# DirectoryIndex: sets the file that Apache will serve if a directory

```

And PREPEND the following text:

```
#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost ip6-localhost 127.0.0.1 192.168.0.0/255.255.255.0
</Location>

```

My understanding is that sed doesn't support multiple line matches, awk seems difficult to do multiple line matches. I'm trying to get perl to work with perl -0777 -pi -e but I can't seem to figure out a regular expression that matches the original pattern. 

I'd prefer to do this as a one liner - not a script because i want it to be portable (i.e. copy and paste as needed). 

Any perl regex experts out there that can help me devise a solution? 

Many thanks in advance
Brad

**EDIT**

The following works:

```
 sed -i -e ':begin;$!N;s/#\n# DirectoryIndex/#\n# Allow server status reports generated by mod_status,\n# with the URL of http:\/\/servername\/server-status\n# Change the ".example.com" to match your domain to enable.\n#\n<Location \/server-status>\n\tSetHandler server-status\n\tOrder deny,allow\n\tDeny from all\n\tAllow from localhost ip6-localhost 192\.168\.0\.0\/255\.255\.255\.0\n<\/Location>\n\n#\n\#DirectoryIndex/;tbegin;P;‌​D' /etc/httpd/conf/httpd.conf 

```

But there's no space between the # and DirectoryIndex.

However if I try to change it to: 

```
sed -i -e ':begin;$!N;s/#\n# DirectoryIndex/#\n# Allow server status reports generated by mod_status,\n# with the URL of http:\/\/servername\/server-status\n# Change the ".example.com" to match your domain to enable.\n#\n<Location \/server-status>\n\tSetHandler server-status\n\tOrder deny,allow\n\tDeny from all\n\tAllow from localhost ip6-localhost 192\.168\.0\.0\/255\.255\.255\.0\n<\/Location>\n\n#\n\# DirectoryIndex/;tbegin;P;‌​D' /etc/httpd/conf/httpd.conf 

```

The sed command hangs and never finishes. I can't seem to figure out why?

The only difference is a space between # and DirectoryIndex.