Hi
I need some help with a task, i am an absolute newbie to any form of shell scripting and request guidance.
Task:
Read a config file in form of name value pair
ex
host=www.test.com
port=8080
binding="dynamic" or "other" or "something else"
key1=value1
key2=value2
key3=value4
policy="<wsp policyFile='mypolicy.policy' >
......
read another file and replace values in the file with value picked up in the first file
second file format
<file port="7001" binding="static" />
<details hos="http//test.com" />
<policy node> insert value of policy here only if binding=dynamic otherwise leave it
</policy node>
</file>
The key/value's might change and hence is there any way to write a generic script to take care of the key values or even otherwise write a hard wired script to pick up the key's and values and update the file according to the requirement.
Thank you for the code. It looks like you are using perl to do some processing and I checked with the box admin and he says we do not have perl installed and it is not on the list to be supported. Is there any other way using just shell scripting to achieve this task.
---------- Post updated at 09:59 AM ---------- Previous update was at 09:09 AM ----------
any suggestions?
---------- Post updated at 10:43 AM ---------- Previous update was at 09:59 AM ----------
i cannot use perl any other suggestions please?
thanks
---------- Post updated at 11:38 AM ---------- Previous update was at 10:43 AM ----------
# ./justdoit
<file port="8080" binding=""dynamic" or "other" or "something else"" />
<details host="www.test.com" />
<policy node> insert value of policy here only if binding=""dynamic" or "other" or "something else"" otherwise leave it
</policy node>
</file>
### justdoit ###
#!/bin/bash
/bin/cp -f file2 orgfile2
for i in `sed '/policy/d;s/\(.*\)=.*/\1/' file1 `
do
x=$(sed -n "/$i/s/\(.*=\)\(.*\)/\1\"\2\"/p" file1)
sed -i "s@$i=[\"0-9a-z\.\/]*@$x@" file2
done
more file2