开发者

vim removing xml tags

I have a one liner in vim which I regularly use for find and replace.

I now want to use it to remove tags - something like this but I looks like I need to escape the / I'm not sure what am I missing.

:%s~<Validator开发者_高级运维>*</Validator>~~g


:%s~<Validator>.*</Validator>~~g

Does the trick


Just topple over that subject and had trouble to remove content over multiple lines. Here is what I come up with:

Input:

<Validator>
    <!-- hello world -->
</Validator>

Vim search replace:

%s~<Validator>\_.\{-}<\/Validator>~~g

The following vim wiki help me find the right syntax: https://vim.fandom.com/wiki/Search_across_multiple_lines


use awk.

awk -vRS="</Validator>"  '{gsub(/<Validator>.*/,"") }1' file

The above removes from tag to tag, even if they span multiple lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜