1

I have below files a) File A

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root xmlns="http://aaa/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema" version="2.0">
    <project name="source">
        <mapping name="m_Source">
            <parameter name="SQL_Query">select  * from $$SCHEMA_NAME."$$TABLE_NAME" where $$COL > $$VALUE and $CONDITIONS</parameter>
            <parameter name="CONDITIONS">Default</parameter>
        </mapping>
    </project>
</root>

b) File b

$$SCHEMA_NAME=test
$$COL=LOAD_DATETIME
$$TABLE_NAME=table1
$$VALUE=1234

I want to replace the values of $$SCHEMA_NAME , $$COL , $$TABLE_NAME, $$VALUE with the values mentioned in right ( i.e. test,DATETIME,table1,1234) in file a

thanks for your help!!

1 Answer 1

1
#!/bin/sh

while read line; do
  a=$(echo $line | awk -F'=' '{print $1}')
  b=$(echo $line | awk -F'=' '{print $2}')
  sed -i "s/$a/$b/" file_a
done < file_b

Brief explanation,

  1. Read each line in file_b and assign the value which is left of equation to 'a', and right one to 'b'.
  2. Use sed to substitute the value in 'a' to the value in 'b' in the file_a.
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please let me know how to redirect the output to a different file ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.