#!/bin/sh

tmpname="/tmp/wordreplacetmp";
if [ $# -lt 3 ] ; then
	echo "Usage: $0 oldstr newstr file1 [file2...]";
else
	old="$1";
	new="$2";
	shift; shift;
	while [ $# -gt 0 ] ; do
		if [ -f "$1" ] ; then
			if grep -q "$old" "$1" ; then
				echo "Processing $1";
				sed "s/$old/$new/g" "$1" > $tmpname;
				mv $tmpname "$1";
			fi;
		else
			if [ -d "$1" ] ; then
				for x in "$1"/* ; do
					eval "$0" "$old" "$new" "$x";
				done;
			else
				echo "$1 not found";
			fi;
		fi;
		shift;
	done;
fi;

	