title: Replace delimited block of text in file with the contents of another file
body: <p>I need to write a simple script to replace a block of text in a configuration file with the contents of another file.</p>
  
  <p>Let's assume with have the following simplified files:</p>
  
  <p><code>server.xml</code></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;Server port="8005" shutdown="SHUTDOWN"&gt;
    &lt;Service name="Catalina"&gt;
      &lt;Connector port="80" protocol="HTTP/1.1"/&gt;
      &lt;Engine name="Catalina" defaultHost="localhost"&gt;
        &lt;!-- BEGIN realm --&gt;
          &lt;sometags/&gt;
          &lt;sometags/&gt;
        &lt;!-- END realm --&gt;
        &lt;Host name="localhost" appBase="webapps"/&gt;
      &lt;/Engine&gt;
    &lt;/Service&gt;
  &lt;/Server&gt;
  </code></pre>
  
  <p><code>realm.xml</code></p>
  
  <pre><code>&lt;Realm className="org.apache.catalina.realm.UserDatabaseRealm"
         resourceName="UserDatabase"/&gt;
  </code></pre>
  
  <p>I want to run a script and have <code>realm.xml</code> replace the contents between the <code>&lt;!-- BEGIN realm --&gt;</code> and <code>&lt;!-- END realm --&gt;</code> lines.  If <code>realm.xml</code> changes then whenever the script is run again it will replace the lines again with the new contents of <code>realm.xml</code>.  This is intended to be run in <code>/etc/init.d/tomcat</code> on startup of the service on multiple installations on which the realm is going to be different.</p>
  
  <p>I'm not so sure how can I do this simply with <code>awk</code> or <code>sed</code>.</p>