I know this question has probably been answered before. I have seen many threads about this in various places, but the answers are not working for me. I am looking for help with an example usage of the 'sed' command.
What I am trying to do is reading some strings from a file and then using those values to replace the strings of few other files
Example:
File1.txt
name:
abcd
age:
22
File2.xml
<root>
<name>xxxx</name>
<age>xxxx</age>
</root>
I am reading name and age from file 1 and trying to replace missing values in the file 2. I have tried to use hard coding and replacing the values in a file :
$name=abcd
$age=22
sed -e 's/.*<name>\([^<]*\)</name>.*/${name}/g' file2.xml
Note: it is not possible to use sed -i. Old version I guess
for the above script I am getting an error
sed: 0602-404 Function s/.*<name>\([^<]*\)</name>.*/${name}/g cannot be parsed.
so first of all I'd like a script to read from the file and then a script to write in to a file without creating a new file.
UPDATE :
for the below added $ mark
$ sed -e 's/.*<name>\([^<]*\)</name>.*/${name}/g' file2.xml
I am getting error./test.sh: line 4: $: command not found