title: processing xml files with bash scripting
body: <p>I have an xml file which has the following structure that contains numerous <code>&lt;Episodes&gt;&lt;/Episodes&gt;</code> to which the structure looks like this:</p>
  
  <pre><code>&lt;Episode&gt;
    &lt;id&gt;4195462&lt;/id&gt;
    &lt;Combined_episodenumber&gt;8&lt;/Combined_episodenumber&gt;
    &lt;Combined_season&gt;2&lt;/Combined_season&gt;
    &lt;DVD_chapter&gt;&lt;/DVD_chapter&gt;
    &lt;DVD_discid&gt;&lt;/DVD_discid&gt;
    &lt;DVD_episodenumber&gt;&lt;/DVD_episodenumber&gt;
    &lt;DVD_season&gt;&lt;/DVD_season&gt;
    &lt;Director&gt;Jay Karas&lt;/Director&gt;
    &lt;EpImgFlag&gt;2&lt;/EpImgFlag&gt;
    &lt;EpisodeName&gt;Karl's Wedding&lt;/EpisodeName&gt;
    &lt;EpisodeNumber&gt;8&lt;/EpisodeNumber&gt;
    &lt;FirstAired&gt;2011-11-08&lt;/FirstAired&gt;
    &lt;GuestStars&gt;Katee Sackhoff|Carla Gallo&lt;/GuestStars&gt;
    &lt;IMDB_ID&gt;&lt;/IMDB_ID&gt;
    &lt;Language&gt;en&lt;/Language&gt;
    &lt;Overview&gt;Karl Hevacheck, aka the Human Genius, gets married.&lt;/Overview&gt;
    &lt;ProductionCode&gt;209&lt;/ProductionCode&gt;
    &lt;Rating&gt;7.6&lt;/Rating&gt;
    &lt;RatingCount&gt;20&lt;/RatingCount&gt;
    &lt;SeasonNumber&gt;2&lt;/SeasonNumber&gt;
    &lt;Writer&gt;Kevin Etten&lt;/Writer&gt;
    &lt;absolute_number&gt;&lt;/absolute_number&gt;
    &lt;filename&gt;episodes/211751/4195462.jpg&lt;/filename&gt;
    &lt;lastupdated&gt;1362547148&lt;/lastupdated&gt;
    &lt;seasonid&gt;471254&lt;/seasonid&gt;
    &lt;seriesid&gt;211751&lt;/seriesid&gt;
  &lt;/Episode&gt;
  </code></pre>
  
  <p>I've figured out how to pull the information between a single tag like so </p>
  
  <pre><code>  value=$(grep -m 1 "&lt;Rating&gt;" path_to_file | sed 's/&lt;.*&gt;\(.*\)&lt;\/.*&gt;/\1/')
  </code></pre>
  
  <p>but I can't find a way to verify that I am looking at the correct episode ie. to check If this is the correct branch which is for <code>&lt;Combined_season&gt;2&lt;/Combined_season&gt;  &lt;EpisodeNumber&gt;8&lt;/EpisodeNumber&gt;</code> before saving the values for specific attributes. I know this can somehow be done using a combination of sed and awk but can't seem to figure it out anyhelp on how I can do this would be greatly appreciated. </p>