开发者

How else can I replace multiple lines through the terminal in a Rails app?

Is there an alternative way to do the following one-liner replacement of text across all files in a Rails app?

perl -pi -e 's/replaceme/thereplacement/g' $(find . -type f)

Perl complains that there are too many files if I include the RAILS_ROOT, but it works for subdirectories.开发者_JAVA百科


I typically use the following to do batch replacement -- e.g. replace all instances of "SomethingOld" with "SomethingNew". The -Z option to grep and the pipe to xargs with the -0 option are necessary for this to work on filenames with spaces.

grep -rlZ 'SomethingOld' * | xargs -0 sed -i '' -e 's/SomethingOld/SomethingNew/g'

Run it from the "root" directory you want to perform the batch replacement in and it will recursively move through all subdirectories. Be warned that this does in-line replacement, so make a backup of the original data first.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜