简体   繁体   中英

How do you remove all the lines between two html tags using sed (or similar)?

I have a file that looks like this:

<HTML>
<HEAD>
< ... stuff ... ></HEAD>
< ... stuff ... >
</HTML>

I'm trying to remove everything between, and including, the HEAD tags, but can't seem to get it to work.

I thought

sed -i -e 's/<HEAD>.*<\/HEAD>//g' file.HTML

should work, but it doesn't remove anything.

sed -i -e '/<HEAD>/,/<\/HEAD>/d' file.HTML

doesn't do anything either. No errors, just nothing.

Is there something wrong with my input file, or is there a different way to go about it?

Delete all lines between tags leaving tags:

sed '/<tag>/,/<\/tag>/{//!d}' input.txt

Delete all lines between tags including tags:

sed '/<tag>/,/<\/tag>/d' input.txt

To change in place use sed -i ... . To change in place while backing up original sed -i.bak ... which will save the original as input.txt.bak .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM