Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Substitute one line of multiple files according to another file

$
0
0
I need to make ~96 configure files from a template config file which has hundreds of rows that looks like:
Code:

template.config:

[LIB]
#average insert size
avg_ins=1000
......
other information omitted

Those config files are named in sequence from S01.config, S02.config, ... etc
with different avg_ins values according to a table
Code:

table.file:

S01 600
S02 710
S03 520
S04 450
......

Only one row needs to be changed with different values of avg_ins . What I tried is first use echo to create a tmp file:
Code:

for i in S{01..96}; do echo "sed 's/avg_ins=1000/avg_ins=600/' template.config > ${i}.config"; done > temp.sh
then manually change the corresponding avg_ins values in the temp.sh file to have the final script like:
Code:

sed 's/avg_ins=1000/avg_ins=600/' template.config > S01.config
sed 's/avg_ins=1000/avg_ins=710/' template.config > S02.config
sed 's/avg_ins=1000/avg_ins=520/' template.config > S03.config
...

Then run the resulted script to have the 96 config files with corresponding avg_ins values.
What is the better way to handle this with awk by read the table.file into array and then substitute the template.config if possible? Thanks a lot!

Viewing all articles
Browse latest Browse all 16232

Trending Articles