findso often, I figured it was a good idea to write this into a post about how I use them.
sed command is one of the undervalued tools I have on my machine. I have
to be honest, I really only use it for its ability to edit files in place but
that alone proved it to be invaluable of a tool. For example, let’s say I’m in a
project that uses RSpec and I want to update a namespace that’s used throughout
the project. I’d use
find to do a search for all of the files containing that
That’d dump the relative path of the file with the text “Site::Models” as well
as the partial context that the text was used. Very nifty! From here, I can
consider running the in-place replacement using
This’ll replace the text and generate a backup of said modified files in the process. Always make backups!
Keeping it DRY
Now, in the practice of keeping things DRY, one can add the following Bash
function to their
~/.bash_profile to make it easy to do a search and replace
from the shell.
Using it would look a bit like:
Bash aliases something like this wouldn’t work within an editor like Vim, so
dropping to the shell using
:shell, running said command and then hitting
to get back to Vim would be an option (that’s how I do it right now).