title: Use sed to modify xml file
body: <p>I need to search an xml file for some text that resides within a start/end tag and if found, to write a line of text just before the end tag.</p>
  
  <p>Eg, in the <strong>XML file</strong> I need to search <strong>MyTag</strong> for "MyText1". If found, add <strong>FoundIt</strong> right before the end tag as shown below</p>
  
  <pre><code> &lt;MyTag&gt;
   &lt;Tag1&gt;MyText1&lt;/Tag1&gt;
   &lt;Tag2&gt;MyText2&lt;/Tag2&gt;
   &lt;Tag3&gt;MyText3&lt;/Tag3&gt;
   &lt;Tag4&gt;MyText4&lt;/Tag4&gt;
   &lt;FoundTag1&gt;FoundIt&lt;/FoundTag1&gt;
   &lt;/MyTag&gt;
  </code></pre>
  
  <p>I was able to use sed to search for the range and print MyText1. But what I really want to be able to do is add the "FoundIt" tag right before the end tag.</p>
  
  <p><strong>Sed Script</strong></p>
  
  <pre><code>/&lt;MyTag&gt;/,/&lt;\/MyTag&gt;/{
  /&lt;Tag1&gt;MyText1&lt;/Tag1&gt;/p
  }
  </code></pre>
  
  <p><strong>XML File Contents</strong></p>
  
  <pre><code>&lt;XmlFile&gt;
  
  &lt;BeginTag&gt;
  &lt;SomeTag&gt;Text&lt;/SomeTag&gt;
  &lt;/BegingTag&gt;
  
  &lt;MyTag&gt;
  &lt;Tag1&gt;MyText1&lt;/Tag1&gt;
  &lt;Tag2&gt;MyText2&lt;/Tag2&gt;
  &lt;Tag3&gt;MyText3&lt;/Tag3&gt;
  &lt;Tag4&gt;MyText4&lt;/Tag4&gt;
  &lt;/MyTag&gt;
  
  &lt;EndTag&gt;
  &lt;SomeTag&gt;Text&lt;/SomeTag&gt;
  &lt;/EndTag&gt;
  
  &lt;/XmlFile&gt;
  </code></pre>