开发者

search and replace in entire project on linux/osx

How would I replace one pattern with another for every file with extension .cc and .h recursively? Not sure if I need to prevent it from going into .svn direct开发者_开发知识库ories.

first attempt

#!/bin/bash
for file in `find . -name '*.cc' -or -name  '*.h'`; do \
    sed -e s/$1/$2/g -i temp $file
done


If your project is managed under linux platform, You can do sth like that inside the bash:

for file in `find . -name '*.cpp' -or -name  '*.h'`; do \
     cat $file | sed s/$1/$2/g > tmp
     mv tmp $file
done

Each svn file has '*-base' extension so all of them will be unchanged. This script will only affect to *h and *cc files.


You can search and replace using regular expressions through certain files in Eclipse project explorer, for example. I'm sure there are lots of tools that can do this, but Elipse comes to mind first.

To do this you need to invoke the "Search" dialog, place your pattern in the search field, specify extensions with a wildcard and press "Replace",

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜