I have a sed command to comment out xml commands
sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml
Takes:
<a>
<!-- Comment -->
<b>
bla
</b>
</a>
Produces:
<!-- Security: <a> -->
<!-- Security: <!-- Comment --> --> // NOTE: there are two end comments.
<!-- Security: <b> -->
<!-- Security: bla -->
<!-- Security: </b> -->
<!-- Security: </a> -->
Ideally I would like to not use my sed script to comment things that are already commented.
Ie:
<!-- Security: <a> -->
<!-- Comment -->
<!-- Security: <b> -->
<!-- Security: bla -->
<!-- Security: </b> -->
<!-- Security: </a> -->
I could do something like this:
sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml
sed 's/^[ \t]*<!-- Security: \(<!--.*-->\) -->/\1/' web.xml
but I think a one liner is cleaner (?)
This is pretty similar: http://stackoverflow.com/questions/436850/matching-a-line-that-doesnt-contain-specific-text-with-regular-expressions