Template replacement with M4
Trying to automate something I had to run a program with a configuration file modified for each run. The easy way to do this is to create a template file and generate the correct configuration file with variable substitution for each run.
This task could be done in a number of ways (sed, perl, shell), to name a few, but as Diego pointed out there is already a tool for this m4. It’s a bit archaic and has odd syntax (think strange quotes or strangely named built-in macros), but it’s ideal for my simple task.
At the end I run it like this:
m4 -Dparam1=value1 -Dparam2=value2 <infile> > <outfile>
As simple as that. Thanks Diego! BTW: some pointers to M4: manual and linux journal article.