tulsantide
Technical User
Hi,
I have 2 files as below.
file1.txt
=========
var1=value1
var2=value2
file2.txt
==========
var1=xxxx
var2=yyyy
var3=zzzzz
I need to look for each key from file1.txt in file2.txt and then replace the value of that key in file2.txt with the value that is in file1.txt. The final result should be as below.
==========
file2.txt
==========
var1=value1
var2=value2
var3=zzzzz
Here is the code that I have. The following "sed" command works fine from command line but not inside the script. Please let me know if I'm doing anything wrong.
===============
#!/bin/sh
cat "file1.txt" | while IFS== read key value
do
echo "key='$key' value='$value'"
sed -i '/^${key}=/s/=.*/=${value}/' file2.txt
done
I have 2 files as below.
file1.txt
=========
var1=value1
var2=value2
file2.txt
==========
var1=xxxx
var2=yyyy
var3=zzzzz
I need to look for each key from file1.txt in file2.txt and then replace the value of that key in file2.txt with the value that is in file1.txt. The final result should be as below.
==========
file2.txt
==========
var1=value1
var2=value2
var3=zzzzz
Here is the code that I have. The following "sed" command works fine from command line but not inside the script. Please let me know if I'm doing anything wrong.
===============
#!/bin/sh
cat "file1.txt" | while IFS== read key value
do
echo "key='$key' value='$value'"
sed -i '/^${key}=/s/=.*/=${value}/' file2.txt
done