src: https://www.internalpointers.com/post/linux-find-and-replace-text-multiple-files

How to replace a string of text in multiple files inside a directory. Useful if you need to mass change a string in multiple files to something else to avoid editing each individually.

Enter the directory, for example we will use "/opt/configs" which would contain many files ending in a ".config" extension.

In this example we will want to change the text "{JAVA}" in all of the files ending with a .config extension inside /opt/configs directory to "/opt/java8/bin/java"...

grep -RiIl '{JAVA}' *.config | xargs sed -i 's|{JAVA}|/opt/java8/bin/java|g'

If there is no output the strings have been replaced. If there is "no input files" output, that means there were no files that needed replacing.

Was this answer helpful? 20 Users Found This Useful (78 Votes)