Reputation: 5745
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
Upvotes: 3
Views: 2535
Reputation: 2311
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
Upvotes: 2
Reputation: 342609
use awk.
awk -vRS="</Validator>" '{gsub(/<Validator>.*/,"") }1' file
The above removes from tag to tag, even if they span multiple lines.
Upvotes: -2