find and replace

Here are to functions that are very useful for development work.

grepr

Search through files under the current directory, ignoring common cruft like tmp files, source control files, and log files.

Usage:

% cd ~/development
% grepr 'string to find'

Code:

grepr() { find . -name '.svn' -prune -o -name '.git' -prune -o -name '*~' -prune -o -name 'log' -prune -o -name 'tmp' -prune -o -type l -prune -o -print0 | xargs -0 grep $1 }

replacer

This is an example function to search and replace all the ruby source files under the current directory.

Usage:

% cd ~/development
% replacer 'string to find' 'string to replace' 

Code:

replacer() { find . -name '*.rb' -print0 -o -name '*.erb' -print0 | xargs -0 replace $1 $2 -- }

The string to find and replace can be regexp.