title: sed: performing a replace on N lines after a pattern match
body: <p>I'm trying to use sed to perform a replace on only N lines after a specific pattern.</p>
  
  <p>Looking at the sed man page it seems like it should be possible to do using addr1,+N syntax. But I can not get it to work.</p>
  
  <pre><code> &lt;data&gt;
    &lt;variable&gt;DebuggerItem.Count&lt;/variable&gt;
    &lt;value type="int"&gt;2&lt;/value&gt;
   &lt;/data&gt;
   &lt;data&gt;
    &lt;variable&gt;Version&lt;/variable&gt;
    &lt;value type="int"&gt;1&lt;/value&gt;
   &lt;/data&gt;
  </code></pre>
  
  <p>The replace I am performing finds the numbers in this markup and increments them by 1. It is as follows.</p>
  
  <pre><code>sed -r 's/([ ]*&lt;value type=)\"(int)\"(&gt;)([0-9]*)(.*)/echo "\1\\"\2\\"\3$((\4+1))\5"/ge' filename
  </code></pre>
  
  <p>I now want to restrict that replacement to just the N lines after the one containing "DebuggerItem.Count". In my current instance N is 1, but I have another example where I would want to perform this for 5 lines after the matched one, so N would be 5.</p>
  
  <p>It can probably be performed with a more complex replace, but ideally I would like to learn more about using addresses with sed.</p>
  
  <p>Note: I had some trouble with the double quotes in the search replace as I needed to double escape them for the following echo. So the search replace is a little convoluted. My apologies.</p>