Here my script to do refactorging with PHP. I've created a command that works inside vim, but only inside a folder.
!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. 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 {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.
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/
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.