In the linux shell, the following command will recursively search and replace all instances of \'this\' with \'that\' (I don\'t have a Linux shell in front of me, but it sho
find . -type f | xargs sed -i '' 's/string1/string2/g'
Refer here for more info.
https://bitbucket.org/masonicboom/serp is a go utility (i.e. cross-platform), tested on OSX, that does recursive search-and-replace for text in files within a given directory, and confirms each replacement. It's new, so might be buggy.
Usage looks like:
$ ls test
a d d2 z
$ cat test/z
hi
$ ./serp --root test --search hi --replace bye --pattern "*"
test/z: replace hi with bye? (y/[n]) y
$ cat test/z
bye
None of the above work on OSX.
Do the following:
perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.txt
The command on OSX should be exactly the same as it is Unix under the pretty UI.
This is my workable one. on mac OS X 10.10.4
grep -e 'this' -rl . | xargs sed -i '' 's/this/that/g'
The above ones use find will change the files that do not contain the search text (add a new line at the file end), which is verbose.
A version that works on both Linux and Mac OS X (by adding the -e
switch to sed
):
export LC_CTYPE=C LANG=C
find . -name '*.txt' -print0 | xargs -0 sed -i -e 's/this/that/g'