我有一个sed命令注释掉XML命令桑达:正则表达式匹配线而不< -
sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml
注意到:
<a>
<!-- Comment -->
<b>
bla
</b>
</a>
产地:
<!-- Security: <a> -->
<!-- Security: <!-- Comment --> --> // NOTE: there are two end comments.
<!-- Security: <b> -->
<!-- Security: bla -->
<!-- Security: </b> -->
<!-- Security: </a> -->
理想我不想用我的sed脚本来评论已经评论过的东西。
即:
<!-- Security: <a> -->
<!-- Comment -->
<!-- Security: <b> -->
<!-- Security: bla -->
<!-- Security: </b> -->
<!-- Security: </a> -->
我可以做这样的事情:
sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml
sed 's/^[ \t]*<!-- Security: \(<!--.*-->\) -->/\1/' web.xml
,但我觉得一个衬垫清洁
这是非常相似的(?):matching a line that doesn't contain specific text with regular expressions
是的,我已经尝试过(和不同的变化),但我无法得到它的工作。它最终没有突出显示。 – sixtyfootersdude 2010-04-05 18:17:42
进一步阅读后,似乎sed不支持这些表达式。你必须使用ssed和活动perl模式(-R)。发现这里的信息:http://sed.sourceforge.net/sedfaq6.html – 2010-04-06 17:27:38
Coool。这也是我的想法。 +1澄清 – sixtyfootersdude 2010-04-06 19:50:16