title: KSH: sed command to search and replace last occurrence of a string in a file
body: <p>I have tried to search for last occurrence in a file using sed. In HP-UX tac option is not available.</p>
  
  <p>For Ex: Below is the data in file,</p>
  
  <pre><code>A|2121212|666666666 | 2|01|2 |B|1111111111 |234234234 |00001148|
  B|2014242|8888888888| 3|12|3 |B|22222222222 |45345345 |00001150|
  C|4545456|4444444444| 4|31|4 |B|3333333333333 |4234234 |00001148|
  </code></pre>
  
  <p>I'm trying:</p>
  
  <pre><code>cat $filename | sed 's/00001148/00001147/g'
  </code></pre>
  
  <p>It is changing from 00001148 to 00001147 for both the occurrence of 00001148.</p>
  
  <p>I have to search for <code>|00001148|</code> of last occurrence and replace with another number. Currently my sed command is changing both two instances of 00001148.</p>