The basic form is:
ack --type=js -f app/views/ | xargs sed -i '' -e 's/search/replace/'
I use ack to generate list of files on which I want to perform the search/replace, and then sed does the actual work. It helps to run this on a clean working directory so I can use git diff
to examine the results and git checkout -- .
to undo everything and try again if I screw everything up.
Lately I've starting playing around with vim's
:bufdo
command to run a command on every file. It's a little easier to remember than the xargs/sed combination, and bufdo let's you use vim macros, which are often more intuitive than regular expressions.See more info on bufdo/argdo commands.