When I run the script I pass in 2 expressions (ex. replace.ksh new old)
I want the script to go line by line for a given file in a given directory and replace the word new with old. Of course in my line where I have the awk statement it is replacing the 2nd word with 1st instead of new with old. The only caveat to this is that this script will be replacing directory structures. We want to go from a development dir to a production dir and make the change to every file within a directory.
Any help with this would be very much appreciated.
for FILE in `ls`
do
while read LINE
do
echo $LINE | grep -q $1
if [ $? -eq 0 ]
then
# print $1 ${1} $2 ${2}
# val=$1 chval=$2
echo $LINE | awk '{sub($1,$2);print}' >> ${FILE}_new
else
echo $LINE >> ${FILE}_new
fi
done < $FILE
# mv TMP_00 $FILE
# rm TMP_00
done