Open the file and replace the variable with actual value

Hi,

i have a sql file named sample.sql. The query is given below.
select count(*) from $TABLE_NAME

In the main script, i am sourcing this sql. I need to replace the $TABLE_NAME with actual value, before running the query. How can i achieve that?

The logic i tried is given below:
VAR1=`cat sample.sql`
echo "$VAR1" > sample_Final.sql

The $TABLE_NAME is not replaced with actual value.

Thanks,
Bharathappriyam

Hi

VAR1=`cat sample.sql`
TABLE_NAME="EMPLOYEE"
eval echo "$VAR1" > sample_Final.sql

Guru.

Thanks Guru. but i am getting the following error.

eval: line 1: syntax error near unexpected token `('

Hi

Modify your query slightly in the sample.sql file:

select count\(*\) from $TABLE_NAME

Guru.