#! /bin/sh
# Please back up your files before runing this script.
# Use sed to replace 'foo' with 'bar' for all .txt files 
#  in the current direcotry tree (including sub-folders).
find . -type f -name '*.txt' -print | while read file
do
  sed 's|foo|bar|g' $file > $file.tmp && mv $file.tmp $file
done

