I have a duplicated block of text I need to delete in a large xml file. I want to keep the first block and delete the second all within the same xml tag. For example:
<!--#if-->
-- several lines of text
<!--#else-->
-- several lines of the same text
<!--#endif-->
I'd like to delete the second block between the else and endif, and keep the keep the block between the if and else tags. Any help much appreciated - the script ends up deleting the entire file.
sed -i '/^<!--#else-->/ {p; :a; N; /^\<\!--\#endif--\>/!ba; s/*.\n//}; d' test.xml
I think this should work for you
sed '/--#else--/,/--#endif--/{//!d}' test.xml
this will delete the lines between else
and endif
if you want to delete else
and endif
as well use this:
sed '/--#else--/,/--#endif--/d' test.xml
in the case you mentioned in the comments try this:
sed -n '/--#else--/,/--#endif--/p' test.xml
-n
is dont print by default and /p
does the print while /!d
does the delete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With