title: Replacing first occurrence line after first matched line
body: <p>Let's assume the following XML file:</p>
  <pre><code>    some text
      &lt;addresses&gt;
        &lt;something/&gt;
      &lt;/addresses&gt;
      some more text
      &lt;addresses xmlns=&quot;namespace&quot;&gt;
        &lt;could be anything/&gt;
      &lt;/addresses&gt;
      some other text
      &lt;addresses&gt;
        &lt;something else/&gt;
      &lt;/addresses&gt;
      ...
  </code></pre>
  <p>I need to replace the first <code>&lt;/addresses&gt;</code> following the first <code>&lt;addresses xmlns=&quot;namespace&quot;&gt;</code> by <code>&lt;/namespace:addresses&gt;</code> so that the file becomes:</p>
  <pre><code>    some text
      &lt;addresses&gt;
        &lt;something/&gt;
      &lt;/addresses&gt;
      some more text
      &lt;addresses xmlns=&quot;namespace&quot;&gt;
        &lt;could be anything/&gt;
      &lt;/namespace:addresses&gt;
      some other text
      &lt;addresses&gt;
        &lt;something else/&gt;
      &lt;/addresses&gt;
      ...
  </code></pre>
  <p>I am aware of <a href="https://stackoverflow.com/questions/32382922/use-sed-to-change-first-occurrence-after-match">this similar thread</a>, but none of the following solution changes anything:</p>
  <pre><code>sed -e '/&lt;addresses xmlns=&quot;namespace&quot;&gt;/!b' -e ':a' -e &quot;s/&lt;\/namespace:addresses&gt;/&lt;\/addresses&gt;/;t trail&quot; -e 'n;ba' -e ':trail' -e 'n;btrail' file.xml
  sed -e &quot;/&lt;addresses xmlns=\&quot;namespace\&quot;&gt;/,/./  s/&lt;\/namespace:addresses&gt;/&lt;\/addresses&gt;/&quot; file.xml
  sed -e &quot;/&lt;addresses xmlns=\&quot;namespace\&quot;&gt;/,/&lt;\/namespace:addresses&gt;/  s/&lt;\/namespace:addresses&gt;/&lt;\/addresses&gt;/&quot; file.xml
  </code></pre>
  <p>For instance:</p>
  <pre><code>sed -e &quot;/&lt;addresses xmlns=\&quot;namespace\&quot;&gt;/,/./  s/&lt;\/namespace:addresses&gt;/&lt;\/addresses&gt;/&quot; file.xml
      some text
      &lt;addresses&gt;
        &lt;something/&gt;
      &lt;/addresses&gt;
      some more text
      &lt;addresses xmlns=&quot;namespace&quot;&gt;
        &lt;could be anything/&gt;
      &lt;/addresses&gt;
      some other text
      &lt;addresses&gt;
        &lt;something else/&gt;
      &lt;/addresses&gt;
      ...
  </code></pre>
  <p>Maybe this issue is linked to the sed I'm using: 4.7-1ubuntu1 on impish/21.10 or even 4.8-1.</p>
  <p>Any suggestion?
  I'm open to any other tool (perl/awk), the simpler, the better.</p>