Unix以递归方式查找和替换?(Unix find and replace recursively?)

编程入门 行业动态 更新时间:2024-10-12 05:55:33
Unix以递归方式查找和替换?(Unix find and replace recursively?)

希望这对于这里的某个人来说是一个快速的工具......我需要在unix中递归地查找和替换一个字符串。

通常情况下,我使用:

perl -e "s/term/differenterm/g;" -pi $(find path/to/DIRECTORY -type f)

但是,我需要替换的字符串包含斜杠,我不确定如何逃脱它们?

所以,我需要做的是:

perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)

FIND ='/ string / path / term'和REPLACE ='/ string / path / newterm'

Hopefully, this will be a quick one for someone here... I need to find and replace a string recursively in unix.

Normally, I use:

perl -e "s/term/differenterm/g;" -pi $(find path/to/DIRECTORY -type f)

But, the string I need to replace contains slashes, and I'm not sure how to escape them?

So, I need to do:

perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)

where FIND = '/string/path/term' and REPLACE = '/string/path/newterm'

最满意答案

您可以使用除/之外的其他字符。 例如:

perl -e "s|FIND|REPLACE|g;" -pi $(find path/to/DIRECTORY -type f)

http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators中的更多信息

You could use other characters besides /. For example:

perl -e "s|FIND|REPLACE|g;" -pi $(find path/to/DIRECTORY -type f)

More info in http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators

更多推荐

本文发布于:2023-08-04 19:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1419260.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   方式   Unix   recursively   replace

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!