sixtyfootersdude
sixtyfootersdude

Reputation: 27231

Regular Expression: back references

sed 's/^\(\h*\)\(.*\)$/\1<!-- \2 -->/' web.xml

I think that this should take this xml:

<a>
  <d>
    bla
  </d>
</a>

And turn it into:

<!-- <a> -->
  <!-- <d> -->
    <!-- bla -->
  <!-- </d> -->
<!-- </a> -->

But what is doing is this:

<!-- <a> -->
<!--   <d> -->
<!--     bla -->
<!--   </d> -->
<!-- </a> -->

Upvotes: 2

Views: 795

Answers (1)

Jo&#227;o Silva
Jo&#227;o Silva

Reputation: 91349

Use [ \t]* instead of \h*, like so:

sed 's/^\([ \t]*\)\(.*\)$/\1<!-- \2 -->/' web.xml

Here's a list of sed's escape (meta) characters.

Upvotes: 1

Related Questions