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:
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:
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!
the string concatenation might not work correctly for redirection file names on all system unless parenthesized (worked for me...)
ALL awk s will run out of file descriptors, some sooner (about 10), others later. So closing them if no more needed puts you on the safe side in either case at the (small) cost of a file operation.
Expanding a little bit on what RudiC said: The standards do not specify the precedence of string concatenation and input or output redirection. So the statement:
print TMP SUP > $1".config"
can be evaluated as if it were written as:
print TMP SUP > ($1".config")
(as it is with gawk and many other versions of awk ), or as:
(print TMP SUP > $1)".config"
(as it is with awk on BSD systems, OS X systems, and many others). Explicitly adding the parentheses makes it clear which you want and makes that part of your code work with any version of awk in case you ever try to move your script to a different operating system.
And since I learned how to use awk on a system that only allowed ten open file descriptors (including the current input file and standard output), I always close file descriptors I no longer need unless I know (as part of the script specifications) that fewer than eight additional input and output files will be used during the lifetime of the script.