UNIX – Replacing variables in sql with matching values from .profile file

I am trying to write a shell which will take an SQL file as input. Example SQL file:


Now the script should extract all variables, which in this case everything starting with %%. So the output file will be something as below:


Now I should be able to extract the matching values from the user’s .profile file for these variables and create the SQL file with the proper values.

    FROM tempdb.TBL_abc
  WHERE CITY = 'Chicago'

As of now I am trying to generate the file1 which will contain all the variables. Below code sample –

sed "s/[(),']//g" "T:/work/shell/sqlfile1.sql" | awk '/%%/{print $NF}' | awk '/%%/{print $NF}' > sqltemp2.sql

takes me till


Can someone help me in getting to file1 listing the variables?

Source: shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.