I have a file (data.dat) which contains 3 columns. I want to read in two of them with the shell script and fill the contents into a template file.
The file looks like this:
12 180 2390
14 177 2210
16 173 2130
...
So far I can do that with one variable (which is column 2 in the data-file) as follows:
for a in `cat data.dat | gawk '{print $2}'`; do
sed s/A/$a/ daily.template daily.template > daily.inp
done
Now I want to read in column 3 as well and give the according value (b) of the same line as column 2 to the same template. The template contains variables called "A" and "B". I cannot do a nested for loop as I don't want to iterate each value of a over each value of b.
How can I achieve this?
Addition:
First of all thanks for all your help!
Yes, it might be more easy to understand if I give more information about the daily.template file. It is looking similiar to:
dens_column O3 300.00
dens_column h20 B
sza A
day_of_year 172
output sum
...
A and B should be replaced in every loop over the lines. The first column in data.dat does not mean anything, it just displays the time of a measurement and this parameter is not needed in "daily.inp". I just want one "daily.inp" for each line where A and B are replaced with the according value of column 2 and 3 in the according line. So a daily.inp file like:
dens_column O3 300.00
dens_column h20 2390
sza 180
day_of_year 172
output sum
...
Then the next file separate:
dens_column O3 300.00
dens_column h20 2210
sza 177
day_of_year 172
output sum
...
And so on...
daily.templatecontains the same number of lines asdata.dat? And each line indaily.templatehas variablesAandB? And each line indata.datshould be matched up with the same line indaily.template? Are both files in the expected order? Does the12,14,16have any meaning? Does it also appear indaily.template?daily.templateand the expected output.>daily.inpafter thedone.