views:

55

answers:

1
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> -->
+1  A: 

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

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

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

JG
Huh, you are correct. That worked. Why wasn't \h working? Is it not supported by sed?
sixtyfootersdude
Maybe just in perl
sixtyfootersdude
Yes, sed's regular expression support is pretty basic. Most regex engines support the meta-character `\s` and the class `[:space:]` for white space.
JG