Replacing a block with another block

I’m trying to add the following lines after redirectPort=“8443”:
proxyName=“mywebsitename.com
proxyPort=“443”
scheme=“https”>
However, there are multiple lines of redirectPort=“8443” in the document, so if I use the blockinfile option, it adds those lines to the wrong section of the document.

The section I want to add it to looks like this:

    <Connector
            port="1234"
            protocol="HTTP/1.1"

            maxThreads="150" minSpareThreads="25"
            connectionTimeout="20000"
            disableUploadTimeout="true"
            acceptCount="100"

            enableLookups="false"
            maxHttpHeaderSize="8192"

            useBodyEncodingForURI="true"
            URIEncoding="UTF-8"

            redirectPort="8443">

The only defining feature between this section and other sections is the Service name = “Catalina”. I thought maybe I could replace this entire Section with the same section, but with additional lines, but I’m having trouble doing that. Is it possible to replace an entire block with another block of lines when everything inside of the block repeats in the document?

This is what I want it to look like:

    <Connector
            port="1234"
            protocol="HTTP/1.1"

            maxThreads="150" minSpareThreads="25"
            connectionTimeout="20000"
            disableUploadTimeout="true"
            acceptCount="100"

            enableLookups="false"
            maxHttpHeaderSize="8192"

            useBodyEncodingForURI="true"
            URIEncoding="UTF-8"

            redirectPort="443"
            proxyName="mywebsitename.com"
            proxyPort="443"
            scheme="https">

You might want to take a look at the community.general.xml module. That might be better suited for this. (I’ve never used it, so no idea how well or not it will work for this.)

1 Like

I think the problem I’m having is with my regexp. I am taking two lines out as a sample and using grep -P to find the lines in the file and it’s not returning any results. For whatever reason it doesn’t like something like regexp: ‘URIEncoding=“UTF-8”\s*\n\s*redirectPort=“8443”>’
If I do the URIEncoding separately, it finds that. If I do the redirectPort separately it finds that, but it doesn’t find them when I add it together with a \n.