ack <search term> -l --print0 | xargs -0 sed -i '' 's/<search term>/<replacement term>/g'
- ack takes a search term, and with the -l flag, it outputs only filenames
- --print0 separates filenames with a null byte instead of a newline. This is nice for filenames that contain spaces (non programmers!)- We take the resulting list and pipe it to xargs which will iterate over each listing and applies the following command. Note the -0 flag so that it knows to look for the null byte character
- Next comes sed. The OS X implementation requires an extension following the -i flag for the in place edit functionality. We pass it an empty string ('') to tell it not to use an extension
- Finally, we do our sed function s/regular expression/replacement/flags. s is for substitute, and /g at the end means to make the substitutions for all matches
Source: https://coderwall.com/p/7ol_ja/os-x-and-project-wide-find-and-replace