fork(1) download
  1. #!/bin/bash
  2. s=' some text
  3. <addresses>
  4. <something/>
  5. </addresses>
  6. some more text
  7. <addresses xmlns="namespace">
  8. <could be anything/>
  9. </addresses>
  10. some other text
  11. <addresses>
  12. <something else/>
  13. </addresses>
  14. ...'
  15. perl -0777 -pe 's~<(addresses)\s+xmlns="namespace">[^<]*(?:<(?!/\1>)[^<]*)*\K</\1>~</namespace:$1>~' <<< "$s"
Success #stdin #stdout 0.01s 5400KB
stdin
Standard input is empty
stdout
    some text
    <addresses>
      <something/>
    </addresses>
    some more text
    <addresses xmlns="namespace">
      <could be anything/>
    </namespace:addresses>
    some other text
    <addresses>
      <something else/>
    </addresses>
    ...