title: sed replace last line matching pattern
body: <p>Given a file like this:</p>
  
  <pre><code>a
  b
  a
  b
  </code></pre>
  
  <p>I'd like to be able to use <code>sed</code> to replace just the last line that contains an instance of "a" in the file.  So if I wanted to replace it with "c", then the output should look like:  </p>
  
  <pre><code>a
  b
  c
  b
  </code></pre>
  
  <p>Note that I need this to work irrespective of how many matches it might encounter, or the details of exactly what the desired pattern or file contents might be.  Thanks in advance.</p>