How can I replace a string in a file(s)?

Replacing all occurrences of one string with another in all files in the current directory recursively (including hidden files):

 find . -type f -exec sed -i 's/foo/bar/g' {} +

Replace only if the file name matches another string or extension:

find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' {} +

Replace only if the string is found in a certain context:

sed -i 's/foo\(.*baz\)/bar\1/' file