Find all files ending with .txt in the current directory and its subdirectories, and replace all occurrences of "foo" with "bar" in each of those files.
find ~ -name '*.txt' -exec sed -i 's/foo/bar/g' {} \;