找到“ string1”并在该字符串和“ string2”之间删除 [英] Find "string1" and delete between that and "string2"

查看:93
本文介绍了找到“ string1”并在该字符串和“ string2”之间删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用命令行和sed。我需要一个命令以递归方式从多个文件中删除。

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

我留下了如下注释:

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

因此,我需要删除字符串中的所有文件中的字符串1,中间的文本和字符串2。

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

不胜感激:)

推荐答案

只需使用地址:

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

更新:要将 sed 命令递归应用于路径下的文件,可以使用 find

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' {} \;

这篇关于找到“ string1”并在该字符串和“ string2”之间删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆