title: How to extract whole records from an xml file if they contain a specific string using standard linux tools
body: <p>I work with XML files containing book data. When investigating data corruption issues I often have to extract the whole records which include a particular string.</p>
  <p>I am struggling to do this with my very limited knowledge of bash scripting and total lack of knowlwdge of other programming languages such as perl.</p>
  <p>I have standard user access to a Linux box (RHEL 4) with no prospect of getting permission to install anything not already present.</p>
  <p>Using standard tools/languages available on this box, can anyone explain how I might look for a particular string and extract any whole records from the file which might contain it?</p>
  <p>E.g. to extract the whole records which contain 'Smith' from the following file.</p>
  <p>Example data:</p>
  <pre><code>&lt;File&gt;
  &lt;Product&gt;
  &lt;Ref&gt;1&lt;/Ref&gt;
  &lt;Title&gt;My Life&lt;/Title&gt;
  &lt;Series&gt;Life Stories&lt;/Series&gt;
  &lt;Author&gt;John Smith&lt;/Author&gt;
  &lt;Price&gt;5.99&lt;/Price&gt;
  &lt;/Product&gt;
  &lt;Product&gt;
  &lt;Ref&gt;2&lt;/Ref&gt;
  &lt;Title&gt;A Story&lt;/Title&gt;
  &lt;Author&gt;Fred Bloggs&lt;/Author&gt;
  &lt;Price&gt;16.99&lt;/Price&gt;
  &lt;/Product&gt;
  &lt;Product&gt;
  &lt;Ref&gt;3&lt;/Ref&gt;
  &lt;Title&gt;Book 1&lt;/Title&gt;
  &lt;Author&gt;Jane Smith&lt;/Author&gt;
  &lt;Price&gt;10.99&lt;/Price&gt;
  &lt;/Product&gt;
  &lt;/File&gt;
  </code></pre>
  <p>Required output:</p>
  <pre><code>&lt;Product&gt;
  &lt;Ref&gt;1&lt;/Ref&gt;
  &lt;Title&gt;My Life&lt;/Title&gt;
  &lt;Series&gt;Life Stories&lt;/Series&gt;
  &lt;Author&gt;John Smith&lt;/Author&gt;
  &lt;Price&gt;5.99&lt;/Price&gt;
  &lt;/Product&gt;
  &lt;Product&gt;
  &lt;Ref&gt;3&lt;/Ref&gt;
  &lt;Title&gt;Book 1&lt;/Title&gt;
  &lt;Author&gt;Jane Smith&lt;/Author&gt;
  &lt;Price&gt;10.99&lt;/Price&gt;
  &lt;/Product&gt;
  </code></pre>
  <p>That is to say everything between the <code>&lt;Product&gt;</code> <code>&lt;/Product&gt;</code> tags for the records containing the string 'Smith'.</p>
  <p>The records may contain different numbers of tags but will always be enclosed in <code>&lt;Product&gt;</code> <code>&lt;/Product&gt;</code> tags.</p>
  <p>I appreciate the perfect result may not be possible every time without using more specialist tools but I simply don't have them available to me. Anything which gets me close would be great.</p>
  <p>I'm thinking the script would read each record in the file, look for the string within each record in turn and redirect those records which match to an output. However, I am struggling to find the answer anywhere.</p>
  <p>Many thanks for any help you can offer.</p>