'remove html tag contains a word sed

In config file i have several this

 <tagwidth> <!-- Short -->
    <x>213</x>
    <y>590</y>
    
</tagwidth>

and all tags are same name but only what is changed is text after (Short, Long, Medium, etc).

    <tagwidth> <!-- Short -->
        <x>213</x>
        <y>590</y>
        
    </tagwidth>
<tagwidth> <!-- Medium -->
        <x>413</x>
        <y>890</y>
        
    </tagwidth>
<tagwidth> <!-- Long -->
        <x>1213</x>
        <y>1590</y>
        
    </tagwidth>

How to remove whole which contains name Short after it. So i want to remove with Short, whole that x and y lines, basically whole tag. So result must be

 </tagwidth>
<tagwidth> <!-- Medium -->
        <x>413</x>
        <y>890</y>
        
    </tagwidth>
<tagwidth> <!-- Long -->
        <x>1213</x>
        <y>1590</y>
        
    </tagwidth>

i tried with this but didnt help

cat config.xml | sed 's/<tagwidth><!-- Short --></tagwidth>//g'


Solution 1:[1]

You can use

sed -i '/<tagwidth> <!-- Short -->/,/<\/tagwidth>/d' file

Details:

  • -i - GNU sed option to perform changes inline
  • /<tagwidth> <!-- Short -->/,/<\/tagwidth>/ - find a block of lines where the first line contains <tagwidth> <!-- Short --> and the second line contains </tagwidth>
  • d - delete the found match(es).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wiktor Stribiżew