title: Delete the last occurence of a string in a file in unix/linux
body: <p>Need to shift the last VirtualHost string in a file at eof. I tried using sed </p>
  
  <pre><code>#!/bin/bash
  tac infile.txt | sed "s/&lt;\/VirtualHost&gt;//; ta ; b ; :a ; N ; ba" | tac
  echo "&lt;/VirtualHost&gt;" &gt;&gt;infile.txt
  </code></pre>
  
  <p>Current Text:</p>
  
  <pre><code>&lt;/VirtualHost&gt;
  #Added for Patch 
  &lt;LocationMatch ^/bea_wls_internal/&gt;
  RewriteEngine ON
  &lt;/VirtualHost&gt;
  RewriteOptions inherit
  &lt;/LocationMatch&gt;
  </code></pre>
  
  <p>Desired Text: </p>
  
  <pre><code>&lt;/VirtualHost&gt;
  #Added for Patch 
  &lt;LocationMatch ^/bea_wls_internal/&gt;
  RewriteEngine ON
  RewriteOptions inherit
  &lt;/LocationMatch&gt;
  &lt;/VirtualHost&gt; 
  </code></pre>