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
更多推荐
发布评论