rreddy rreddy - 1 year ago 86
Bash Question

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

How to find and replace every occurrence of




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

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download