Find “string1” and delete between that and “string

2019-06-03 05:55发布

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条回答
在下西门庆
2楼-- · 2019-06-03 06:35

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' {} \;
查看更多
登录 后发表回答