Klausi
Klausi

Reputation: 11

Bash: remove html tag from page

I have some html code

<div><img src="..." /></div>

and I would like to remove the img tag from it to get:

<div></div>

I wrote a bash script with the same commands I did in emacs:

cat "$1"|sed 's/</\n</g'|sed 's/>/>\n/g'|sed 's/^<img.+//g' > "$2"

but It didn't work. It seems that sed doesn't work in line breaks. Any suggestions?

I also tried:

sed 's/<img.+>//g'

but this removes too much code.

Thanks in advance.

Upvotes: 0

Views: 268

Answers (1)

Klausi
Klausi

Reputation: 11

The pattern sed 's/<img[^>]*>//g' seems to fit my needs.

Upvotes: 1

Related Questions