0

For the text ABC<img src="test"></a>, I'm hoping to get rid of the <img ...> part, in other words, I want the result to be displayed as: ABC</a>. I tried several patterns, but none of them worked.

echo 'ABC<img src="test"></a>'|sed -e "s/<img src=\".*>//g"
ABC

I don't know whether I should escape < or >, When I did, I got the following result:

echo 'ABC<img src="test"></a>'|sed -e "s/\<img src=\".*\>//g"
ABC<>

Can anyone clarify these results and give me a satisfying one?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Searene
  • 25,920
  • 39
  • 129
  • 186

1 Answers1

1

Just indicate that you want to remove from <img + any set of characters until a new > is found.

sed "s/<img[^>]*>//g"

Test

$ sed "s/<img[^>]*>//g" <<< 'ABC<img src="test"></a>'
ABC</a>
fedorqui
  • 275,237
  • 103
  • 548
  • 598