configuration and template file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting configuration and template file
# 1  
Old 05-01-2008
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
# 2  
Old 05-01-2008
Use sed. Google for some sed documentation, look specifically for replacing strings.
# 3  
Old 05-01-2008
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
# 4  
Old 05-02-2008
Thanks for replying..

I am getting the below error.

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

Thanks
Ammu
# 5  
Old 05-02-2008
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
# 6  
Old 05-05-2008
Code:
nawk 'BEGIN{FS="="}
{
if(NR==FNR)
	var[NR]=$2
else
{
	t=substr($0,length($0))
	sub(/\$var./,var[t],$0)
	print $0
}
}' file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge strings from a file into a template

I am preparing a morphological grammar of Marathi to be placed in open-source. I have two files. The first file called Adverbs contains a whole list of words, one word per line A sample is given below: आधी इतक इतपत उलट एवढ ऐवजी कड कडनं कडल कडील कडून कडे करता करिता खाल (2 Replies)
Discussion started by: gimley
2 Replies

2. Shell Programming and Scripting

Inputing info from a CSV file and filling a template file

Hi, I have a .csv file that contains a variety of fields for 60 clients: USERNAME, PASSWORD, and COMMENTS. I have a template file which contains a great deal of data for each client and has the fields USERNAME, PASSWORD, and COMMENTS that has to be filled with the values of USERNAME,... (1 Reply)
Discussion started by: mojoman
1 Replies

3. Linux

Search a template file and replace with input

Hi I have a CommonTemplateStop.template file . Inside the file i need to replace the variables DepName and CompInsName with the values(Trade and TradeIns) specified in the script. I have written the below .sh script in linux server which will read the .template file and has to replace the 2... (8 Replies)
Discussion started by: samrat dutta
8 Replies

4. UNIX for Dummies Questions & Answers

XML File Generation - Template Help

Hi, I have hit a bit of a brick wall.:confused: need the following code edited: echo "<?xml version=\"1.0\"?><dailyBalance_ROWSET>" > ${DataDir}/${extract_script}${ApplicationDate}.${Suffix} RunSQL ${extract_script} ${ActionFlag} echo "</dailyBalance_ROWSET>" >>... (2 Replies)
Discussion started by: Xergxes7
2 Replies

5. Shell Programming and Scripting

Creating a larger .xml file from a template(sample file)

Dear All, I have a template xml file like below. ....Some---Header....... <SignalPreference> ... <SignalName>STRING</SignalName> ... </SignalPreference> ......Some formatting text....... <SignalPreference> ......... ... (3 Replies)
Discussion started by: ks_reddy
3 Replies

6. Shell Programming and Scripting

filling in strings in a template file using awk

Hi all, I have a template form to fill in for quite a number of files and I want to automate the filling-in process. the concept seemed to be simple but i cant get it work. the template form is a text file containing the information below: File Name: Date Created: Contents: I need to... (4 Replies)
Discussion started by: ida1215
4 Replies

7. Shell Programming and Scripting

Reading columns, making a new file using another as template

Hi fellas, I have two files such as: File 1 interacao,AspAsp,AspCys,CysAsp,CysCys,classe File 2 interacao,AspAsp,CysAsp,AspCys,CysCys,classe beta_alfa, DA, CA, DD, CD,ppi Thus, I want to make a File 3 using the File 1 as model: e.g. File 3... (2 Replies)
Discussion started by: valente
2 Replies

8. Shell Programming and Scripting

xmlstarlet template parse small xml file

I have a file like: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <geonames> <geoname> <toponymName>Palos Verdes</toponymName> <name>Palos Verdes</name> <lat>42.1628912</lat> <lng>-123.6481235</lng> <geonameId>5718340</geonameId> <countryCode>US</countryCode>... (4 Replies)
Discussion started by: unclecameron
4 Replies

9. Shell Programming and Scripting

Using SED to generate new file from template

Hi there! I am using a BASH script to read a CSV file (containing variable values)using while read, and for every record I want SED to get a template from a file, and using the variables read from the CSV, write a new file. #!/bin/bash current_ifs=$IFS ; #backup original IFS, need ","... (12 Replies)
Discussion started by: ppucci
12 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question