Find “string1” and delete between that and “string

2019-06-03 06:03发布

问题:

I'm using command line and sed. I need a command to delete from multiple files recursively.

I have left comments such as:

<!--String 1 -->
Code to delete goes here
<!--String 2 -->

So I need to delete string 1, the text in between and string 2, in all files in the current directory and below.

Would appreciate any help :)

回答1:

Just use addresses:

sed -e '/<!--String 1 -->/,/<!--String 2 -->/d'

Update: to apply the sed command recursively to files under a path, you can use find:

find /path/to/directory -type f -exec sed -e '/<!--String 1 -->/,/<!--String 2 -->/d' {} \;