When trying rdrtx1's script in message #6 in this thread on OS X, I get errors about printf not recognizing %V as a format specifier.
The following script seems to work with your input files. (Note that I also changed the 01-01-2012
in the 1st line in your template to %VAR_DATE_1%
and added a line to your .csv file for testing purposes. If you don't make this change to the template, it won't affect your output.) For testing I used the following script:
#!/bin/ksh
awk -F ', ' 'FNR==NR{
for(i = 1; i < NF; i++)
v["VAR_" $1 "_" i] = $(i + 1)
next
}
{ for(i = 2; i <= NF; i += 2)
if($i in v)
$i = v[$i]
print $0
}' prices.csv FS='%' OFS="" template.txt
When I run this script given a file named prices.csv that contains:
DATE, 12-06-2012
USOR2GB, 10.25, 9.23, 8.47, 8.21
USOR4GB, 10.55, 9.53, 8.69, 8.58
USOR8GB, 10.75, 9.83, 8.97, 8.91
and a file named template.txt that contains:
Rateband prices per %VAR_DATE_1%
=========================================
PRODUCT with 5+ 10+ 50+ and 100+ prices
=========================================
Original 2GB: %VAR_USOR2GB_1% %VAR_USOR2GB_2% %VAR_USOR2GB_3% %VAR_USOR2GB_4%
Original 4GB: %VAR_USOR4GB_1% %VAR_USOR4GB_2% %VAR_USOR4GB_3% %VAR_USOR4GB_4%
Original 8GB: %VAR_USOR8GB_1% %VAR_USOR8GB_2% %VAR_USOR8GB_3% %VAR_USOR8GB_4%
it produces the output:
Rateband prices per 12-06-2012
=========================================
PRODUCT with 5+ 10+ 50+ and 100+ prices
=========================================
Original 2GB: 10.25 9.23 8.47 8.21
Original 4GB: 10.55 9.53 8.69 8.58
Original 8GB: 10.75 9.83 8.97 8.91
Note, however, that this script will not work if your template file contains any other percent characters. If it does contain percent characters that are not included in macros that are to be expanded, a more complex script would be required.