title: How to replace the nth occurrence of a string using sed
body: <p>Is there any way to replace the nth occurrence of a string in a file using sed?</p>
  
  <p>I'm using  <code>sed -i '0,/jack.*/ s//jill/'</code> to replace the first occurrence. </p>
  
  <p>How can i change it so that it replaces the nth occurrence?</p>
  
  <p>My file contents the following lines:</p>
  
  <pre><code>first line
  second line
  third line
  jack=1
  fifth line
  jack=
  seventh line
  </code></pre>
  
  <p>I don't know the value after <code>jack=</code>, it can be anything or nothing.</p>
  
  <p>I want to replace the 2nd occurrence of <code>jack=</code> and anything that follows it with <code>jill</code>.</p>