tulsantide
Technical User
Hi,
I need to replace the whole line in file2.txt based on the key in file1.txt
file1.txt
=========
ui_home=/export/appl/website/${ui.root}
java_home=/export/appl/java/ssss
domain.host.list=server-1,server-2
domain.server.cluster.list=server-1:cluster1,server-2:cluster2
runtime=/export/appl/website/runtime
ldap.provider.url=ldap://ldapserver:280
file2.txt
========
ui_home=/export/appl/ui/${test}
java_home=/export/appl/java/zzzzz
domain.host.list=server-10,server-12
domain.server.cluster.list=server-10:cluster1,server-12:cluster2
runtime=/export/appl/website/runtime
ldap.provider.url=ldap://ldapserver:480
ai.home=/export/appl/ddss/shss
Result should be as below
======
file2.txt
=======
ui_home=/export/appl/website/${ui.root}
java_home=/export/appl/java/ssss
domain.host.list=server-1,server-2
domain.server.cluster.list=server-1:cluster1,server-2:cluster2
runtime=/export/appl/website/runtime
ldap.provider.url=ldap://ldapserver:280
ai.home=/export/appl/ddss/shss
Here is the script that I came up, which is giving the following error.Please help me on this.
============================================================
Error:sed: -e expression #1, unknown option to `s'
==========================================================
#!/bin/sh
for i in `cat file1.txt`
do
key=`echo $i|awk -F= '{print $1}'`
value=`echo $i|awk -F= '{print $2}'`
echo "key=$key value=$value"
sed -i "s/${key}.*/$i/" test2.txt
if [ $? -ne 0 ];then
printf "************************************************************************\n"
echo "Token replacement in file2.txt failed"
printf "\n************************************************************************\n"
exit 1
fi
done
I need to replace the whole line in file2.txt based on the key in file1.txt
file1.txt
=========
ui_home=/export/appl/website/${ui.root}
java_home=/export/appl/java/ssss
domain.host.list=server-1,server-2
domain.server.cluster.list=server-1:cluster1,server-2:cluster2
runtime=/export/appl/website/runtime
ldap.provider.url=ldap://ldapserver:280
file2.txt
========
ui_home=/export/appl/ui/${test}
java_home=/export/appl/java/zzzzz
domain.host.list=server-10,server-12
domain.server.cluster.list=server-10:cluster1,server-12:cluster2
runtime=/export/appl/website/runtime
ldap.provider.url=ldap://ldapserver:480
ai.home=/export/appl/ddss/shss
Result should be as below
======
file2.txt
=======
ui_home=/export/appl/website/${ui.root}
java_home=/export/appl/java/ssss
domain.host.list=server-1,server-2
domain.server.cluster.list=server-1:cluster1,server-2:cluster2
runtime=/export/appl/website/runtime
ldap.provider.url=ldap://ldapserver:280
ai.home=/export/appl/ddss/shss
Here is the script that I came up, which is giving the following error.Please help me on this.
============================================================
Error:sed: -e expression #1, unknown option to `s'
==========================================================
#!/bin/sh
for i in `cat file1.txt`
do
key=`echo $i|awk -F= '{print $1}'`
value=`echo $i|awk -F= '{print $2}'`
echo "key=$key value=$value"
sed -i "s/${key}.*/$i/" test2.txt
if [ $? -ne 0 ];then
printf "************************************************************************\n"
echo "Token replacement in file2.txt failed"
printf "\n************************************************************************\n"
exit 1
fi
done