title: Shell | removing repetitive lines
body: <p>I need to write a Bash script for removing similar lines from an output file.
  My output file is always same. </p>
  
  <p>Lines 1 &amp; 2 should stay and other lines similar to these two need to be deleted.</p>
  
  <pre><code>1:  &lt;/UsageData&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2:  &lt;UsageData broadcastday="2016-03-16"&gt;
  </code></pre>
  
  <p>The date varies.</p>
  
  <p>The last line should be kept. E.g.</p>
  
  <p><code>&lt;/UsageData&gt;</code></p>
  
  <p>I'm new to shell programming and I can't figure out how to do it. </p>
  
  <p>Here is my sample XML:</p>
  
  <blockquote>
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;UsageData broadcastday="2016-03-16"&gt; 
      &lt;Hh hhID="48800301"&gt; 
          &lt;Inst instID="000002B9"/&gt; 
          &lt;Live&gt; 
              &lt;Station&gt;516&lt;/Station&gt; 
              &lt;From&gt;Wed Mar 16 2016 09:52:47 GMT+0000 (UTC)&lt;/From&gt; 
              &lt;DurSec&gt;58077&lt;/DurSec&gt; 
              &lt;Viewer&gt; 
                  &lt;HhMem&gt;569de65c9c3ab0cf7bfa2df2&lt;/HhMem&gt; 
              &lt;/Viewer&gt; 
          &lt;/Live&gt; 
      &lt;/Hh&gt; 
      &lt;Hh hhID="46920403"&gt; 
          &lt;Inst instID="000002A8"/&gt; 
          &lt;Live&gt; 
              &lt;Station&gt;5000&lt;/Station&gt; 
              &lt;From&gt;Wed Mar 16 2016 12:42:17 GMT+0000 (UTC)&lt;/From&gt; 
              &lt;DurSec&gt;47908&lt;/DurSec&gt; 
              &lt;Viewer&gt; 
                  &lt;HhMem&gt;56caee95f915e09335fd976f&lt;/HhMem&gt; 
              &lt;/Viewer&gt; 
          &lt;/Live&gt; 
      &lt;/Hh&gt; 
  &lt;/UsageData&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;UsageData broadcastday="2016-03-16"&gt; 
      &lt;Hh hhID="15260304"&gt; 
          &lt;Inst instID="000000A5"/&gt; 
          &lt;Live&gt; 
              &lt;Station&gt;5000&lt;/Station&gt; 
              &lt;From&gt;Wed Mar 16 2016 12:57:48 GMT+0000 (UTC)&lt;/From&gt; 
              &lt;DurSec&gt;28814&lt;/DurSec&gt; 
              &lt;Viewer&gt; 
                  &lt;HhMem&gt;565f181dd830d3cc7057c0b9&lt;/HhMem&gt; 
              &lt;/Viewer&gt; 
          &lt;/Live&gt; 
      &lt;/Hh&gt; 
  &lt;/UsageData&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;UsageData broadcastday="2016-03-16"&gt; 
      &lt;Hh hhID="50100501"&gt; 
          &lt;Inst instID="0000022D"/&gt; 
          &lt;Live&gt; 
              &lt;Station&gt;560&lt;/Station&gt; 
              &lt;From&gt;Wed Mar 16 2016 14:21:19 GMT+0000 (UTC)&lt;/From&gt; 
              &lt;DurSec&gt;41967&lt;/DurSec&gt; 
              &lt;Viewer&gt; 
                  &lt;HhMem&gt;56c4412de6a8ff4da18fd4ae&lt;/HhMem&gt; 
                  &lt;HhMem&gt;56c4412de6a8ff4da18fd4cb&lt;/HhMem&gt; 
              &lt;/Viewer&gt; 
          &lt;/Live&gt; 
      &lt;/Hh&gt; 
  &lt;/UsageData&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;UsageData broadcastday="2016-03-16"&gt; 
      &lt;Hh hhID="36110404"&gt; 
          &lt;Inst instID="00000104"/&gt; 
          &lt;Live&gt; 
              &lt;Station&gt;545&lt;/Station&gt; 
              &lt;From&gt;Wed Mar 16 2016 15:01:04 GMT+0000 (UTC)&lt;/From&gt; 
              &lt;DurSec&gt;671&lt;/DurSec&gt; 
              &lt;Viewer&gt; 
                  &lt;HhMem&gt;568ce8acbd0e486a951d41ce&lt;/HhMem&gt; 
                  &lt;HhMem&gt;568ce8acbd0e486a951d41dc&lt;/HhMem&gt; 
                  &lt;HhMem&gt;568ce8acbd0e486a951d41c5&lt;/HhMem&gt; 
              &lt;/Viewer&gt; 
          &lt;/Live&gt; 
      &lt;/Hh&gt; 
  &lt;/UsageData&gt;
  </code></pre>
  </blockquote>