Today I wanted to change all my .emacs.d/ files in one go. I’ve previously prefixed my functions with bj/ but find that too hard to type fast. bj: seems to be an easier alternative. Not wanting to manually edit all those files I looked into grep and sed to help me out!

First step: what are the files that have bj/ in it?

$ grep "bj/" * -Rl

Second step: replace the file contents which match bj/ with bj:

$ sed -i 's/bj\//bj:/g' file.el

-i makes file.el to serve as output as well.

Third step: putting it all together.

$ for f in `grep "bj/" * -Rl`; do sed -i 's/bj\/bj:/g' $f; done

Nice work!

PS. It took me about the same amount of time to write this post and to commit this change.