Using sed in ksh to find and replace string

Hi All,

I have a file in which contains location of various data files. I want to change locations using sed. Find and replace strings are in a separate file. Content of this file (/tmp/tt) -

/dd/pp/test/test/1/ /pp/aa/test/dg1/
/dd/pp/test/test/2/ /pp/aa/test/dg2/
/dd/pp/test/test/3/ /pp/aa/test/dg3/

This is how I am trying to get desired result-

cat /tmp/tt | while read LINE
do
  FND=`echo $LINE | awk '{print $1}'`
  REP=`echo $LINE | awk '{print $2}'`
  sed "s=/${FND}=${REP}=" /tmp/ccf_temp.sql > /tmp/tmp.sql && mv /tmp/tmp.sql /tmp/ccf_temp.sql
done

Above is not working. However on command line if I give find and replace string directly, sed is working fine. For example below is fine

$>sed "s/dd/pp/test/test/1//pp/aa/test/dg1/=" /tmp/ccf_temp.sql > /tmp/tmp.sql

So I believe it is the variable that is cauing issue.

Can someone help please.

Thanks in advance for your time

Untested.

while read a b
do
    sed -i "s|$a|$b|g" /tmp/ccf_temp.sql
done < /tmp/tt

Thanks Balajesuri. It was very kind of you.

I had to tweak your code a bit to make it work.

I was getting invalid option "i" if I used sed -i. So this is what worked for me-

while read a b
do
sed "s|$a|$b|g" /tmp/ccf_temp.sql > /tmp/tmp.sql && mv /tmp/tmp.sql /tmp/ccf_temp.sql
done < /tmp/tt