#!/bin/ksh # -------------------------------------------------------------------- # Change a string in all files in the current directory # NOTES: Remember to change the FROM and TO variables # Frank Naude - Oracle FAQ # -------------------------------------------------------------------- FROM="ORA920" TO="ORA1020" EXCLUDE=`basename $0` # find . -name ... -exec grep -l ... {} \; | while read FILE for FILE in `grep -l ${FROM} * | grep -v $EXCLUDE` do # Make backup of file,,, cp ${FILE} ${FILE}.bak # Edit the file... sed "s/${FROM}/${TO}/g" <${FILE} >/tmp/sed_work # Copy back if OK... if [ -s "/tmp/sed_work" ]; then mv /tmp/sed_work ${FILE} else echo Something is wrong - abort exit -1 fi done