[英]Wrong command using sed, in more folders, listed with grep
Here my script to do refactorging with PHP. 这里我的脚本用PHP进行重构。 I've created a command that works inside vim, but only inside a folder.
我创建了一个在vim内有效的命令,但仅在文件夹内有效。
!for i in `grep -Rl OldName foldername/`; do sed -i 's/OldName/NewName/g' $i; done;
What I am asking here, is the update to this script, that allow me to run sed in more folders, with one single command. 我在这里要问的是对此脚本的更新,该更新使我可以使用一个命令在更多文件夹中运行sed。 I've tried this:
我已经试过了:
!for i in `grep -Rl OldName .{a,b,c}/`; do sed -i 's/OldName/NewName/g' $i; done;
But does not works. 但是不起作用。 Can some one suggest me the fix?
有人可以建议我解决吗?
You can just use find
and sed
like this: 您可以像这样使用
find
和sed
:
find {src,test,scripts} -type f -exec sed -i 's/OldName/NewName/g' {} +
find
command will find all the files in folders src,test,scripts
in current directory and sed
will perform inline substitution. find
命令将查找当前目录中 src,test,scripts
文件夹中的所有文件,而sed
将执行内联替换。
for i in $(grep -Rl OldName src/ test/ scripts/); do sed -i 's/OldName/NewName/g' "$i" ; done;
You can give a list of directories to search as shown above. 您可以提供要搜索的目录列表,如上所示。 like
src/
test/
scripts/
. 像
src/
test/
scripts/
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.