title: How can I can insert the contents of a file into another file right before a specific line
body: <p>How can I can insert the contents of a file into another file right before a specific line using sed?</p>
  
  <p>example I have file1.xml that has the following:  </p>
  
  <pre><code>        &lt;field tagRef="376"&gt;
          &lt;/field&gt;
          &lt;field tagRef="377"&gt;
          &lt;/field&gt;
          &lt;field tagRef="58"&gt;
          &lt;/field&gt;
          &lt;group ref="StandardMessageTrailer" required="true"/&gt;
      &lt;/fieldList&gt;
  &lt;/message&gt;
  </code></pre>
  
  <p>and file2.xml has the following:  </p>
  
  <pre><code>        &lt;field tagRef="9647"&gt;
              &lt;description&gt;Offset&lt;/description&gt;
          &lt;/field&gt;
          &lt;field tagRef="9648"&gt;
              &lt;description&gt;Offset Units/Direction&lt;/description&gt;
          &lt;/field&gt;
          &lt;field tagRef="9646"&gt;
              &lt;description&gt;Anchor Price&lt;/description&gt;
          &lt;/field&gt;
  </code></pre>
  
  <p>how can I insert the contents of file2 into file1 just before   </p>
  
  <pre><code>&lt;group ref="StandardMessageTrailer" required="true"/&gt;
  </code></pre>
  
  <p>so it will look like this:  </p>
  
  <pre><code>       &lt;field tagRef="376"&gt;
          &lt;/field&gt;
          &lt;field tagRef="377"&gt;
          &lt;/field&gt;
          &lt;field tagRef="58"&gt;
          &lt;/field&gt;
          &lt;field tagRef="9647"&gt;
              &lt;description&gt;Offset&lt;/description&gt;
          &lt;/field&gt;
          &lt;field tagRef="9648"&gt;
              &lt;description&gt;Offset Units/Direction&lt;/description&gt;
          &lt;/field&gt;
          &lt;field tagRef="9646"&gt;
              &lt;description&gt;Anchor Price&lt;/description&gt;
          &lt;/field&gt;
          &lt;group ref="StandardMessageTrailer" required="true"/&gt;
      &lt;/fieldList&gt;
  &lt;/message&gt;
  </code></pre>
  
  <p>I know how to insert after that line using </p>
  
  <pre><code>sed 'group ref="StandardMessageTrailer"/r file2.xml' file1.xml &gt; newfile.xml  
  </code></pre>
  
  <p>but I want to insert it before.  </p>
  
  <p>appreciate the help  </p>