rreddy rreddy - 5 months ago 7
Bash Question

Grep/Sed: How to do a recursive find/replace of a string?

How to find and replace every occurrence of

httpaccess

with

httpaccessabc

in every file of name "access.html" in a particular folder

Answer
shopt -s globstar
sed -i.bak 's/httpaccess/&abc/g' **/access.html
  • Use globstar with ** to match your filename, recursively.
  • Use sed -i to perform an in-place substitution.

This will create backup files with a suffix .bak. To unset the shell option, use shopt -u globstar afterwards.