Find all files with the extension .txt in the current directory and its subdirectories up to a maximum depth of 3, and replace all occurrences of the word 'foo' with the word 'bar' in each file.
find . -mindepth 1 -maxdepth 3 -type f -name '*.txt' | xargs sed -i 's/foo/bar/g'