#!/bin/ksh # changeword version 1.0 # This script takes 3 argument: # changeword # This script replaces occurences of from_word to to_word if [ $# -lt "3" ] then echo Usage: changeword from_word to_word file exit 1 fi for x do if [ $x != "changeword" ] && [ $x != $1 ] && [ $x != $2 ] then echo "changing $x: \c" # Make sure file is not empty if test -s $x then sed "/$1/s//$2/g" $x > $x.new # Check outputed sed file if test -s $x.new then if cmp -s $x $x.new then echo "file not changed: \c" else cp $x.new $x fi echo "done" else echo "Sed produced an empty file." fi else echo $x" is empty or is not a file." fi rm $x.new fi done