title: Searching a string and replacing another string above the searched string
body: <p>I have a file with the lines below</p>
  
  <pre><code>123
  456
  123
  789
  abc
  efg
  xyz
  </code></pre>
  
  <p>I need to search with <code>abc</code> and replace immediate above <code>123</code> with <code>111</code>.  This is the requirement, <code>abc</code> is only one occurrence in the file but <code>123</code> can be multiple occurrences and 123 can be at any position above <code>abc</code>.
  Please help me.</p>
  
  <p>I have tried with below sed command</p>
  
  <pre><code>sed -i.bak "/abc/!{x;1!p;d;};x;s/123/1111" filename
  </code></pre>
  
  <p>With the above command, it is only replacing <code>123</code>, if <code>123</code> is just above <code>abc</code>, if <code>123</code> is 2 lines above <code>abc</code> then replace is failing.</p>