Replace string in multiple files using find and sed

findrecursivereplacesed

So I've arrived at the conclusion that for recursively replacing all instances of a string in directory (only for .java extensions files) I need to use

find . -type f -name "*.java" -exec sed -i 's/original/result/g' {} +

However what do I do if the string I am trying to replace contains /?

For example I want to replace string /*Comment*/ with a couple normal words, what delimiters should I use, so that sed works properly?

Best Answer

Escape the slash, writing \/ You could also do:

perl -pi -e 's!original!result!g' *java

using ! as a delimiter instead of /. This is a bit shorter than using find & sed.

Related Question