The sed command is not working as expected in csh to remove tags

22 Views Asked by At

Let's assume I have my_file:

First line
<file>dsdsd</file>
Middle line
<file>sdsfs</file>
<file>asasa</file>
End line

After this command:

sed -i '/<file>/,/<\/file>/d' my_file

I expect to see only these lines:

First line
Middle line
End line

Why do I see only the "First line" ? How to fix it ? It's just an example of the text. My goal: remove all tags from the file.

Thanks, Alex

1

There are 1 best solutions below

0
Diego Torres Milano On

You need a regex like this to remove the lines

sed -i '/<file>.*<\/file>/d' my_file

However, if your intention is to parse XML/HTML you may need other tools rather than sed.