I am trying to remove the below section of code from a KML file, ideally using simple Bash/sed code.
I am familiar with removing XML tags using sed
but, I'm not sure how to remove sub-tags matching certain names.
To re-iterate, I need to match and then remove the entire "Overlay" <Folder></Folder>
tag from the KML file.
Attempted Bash Code for Parsing Desired Pattern Match:
grep -B 1 "<name>Overlay</name>" -A 9
KML Code:
<Folder>
<name>Overlay</name>
<open>0</open>
<Style>
<ListStyle>
<listItemType>check</listItemType>
<bgColor>00ffffff</bgColor>
<maxSnippetLines>2</maxSnippetLines>
</ListStyle>
</Style>
</Folder>
This might work for you (GNU sed):
sed '/<Folder>/{:a;N;/<\/Folder>/!ba;/<name>Overlay<\/name>/d}' file
Gather up lines in the range from <Folder>
to </Folder>
and if the collection contains <name>Overlay</name>
delete it.
建议一行gawk
(大多数 Linux 机器中的普通awk
)脚本:
gawk '/<Folder>/,/<\/Folder>/{next}1' input.kml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.