configuration and template file

Hi,

I have a configuration file(which has values) and a template file(where the values are dummied)

Configuration file (a.txt)
--------------------
var1=1521
var2=172.10.10.10
var3=emp
.
.
.
var15=hhhhhhh

Template file (b.txt)
--------------------
The host name is $var2.
The database name is $var3
The port is $var1
.
.
.

Now I want to replace the dummied values in template file(b.txt) with actual value which is in configuration file(a.txt). There are some 15 variable like. Can some tell me what is the best way of doing it. I am looking for something like search in configuration file get a variable and replace that in template file

Thanks in advance
Ammu

Use sed. Google for some sed documentation, look specifically for replacing strings.

hope this helps you.

please paaste this in file and run it.
but remember that this one will work only if you have values like
var1=value

there should not be any spaces between the equal to sign (=)
please replace the input_file and config files.

awk -F = ' BEGIN {
cmd_str=" sed "; }
$0 !~ /^$/ {
cmd_str = cmd_str " -e '\''s?" $1 "?" $2 "?g'\'' ";
}
END { cmd_str = cmd_str " input_file > output_file"; system(cmd_str); } ' config_file

Thanks for replying..

I am getting the below error.

awk: syntax error near line 1
awk: bailing out near line 1

Thanks
Ammu

chappidi_pradee

I tried nawk and it worked. Now how can i pass input.txt and output.txt as a parameter to qwk. I tried -v option but it getting hanged. Can you please let me know

Thanks
Ammu

nawk 'BEGIN{FS="="}
{
if(NR==FNR)
	var[NR]=$2
else
{
	t=substr($0,length($0))
	sub(/\$var./,var[t],$0)
	print $0
}
}' file1 file2