Search code examples
unixtemplate-enginem4

Use m4 templating to templetify file name


I have a project that uses m4 templates to templetify things. What I need to do is to actually create files based on parameters in m4 files. File content will stay the same.

So, let's say I have this:

DEV.m4

define(`A_NODE',`myhostname')
define(`A_NODE_PORT',`1234')

filter.template

aaa=[aaaaa]
bbb=[bbbbb]

I would need to create a file:

filter_%%A_NODE%%_%%A_NODE_PORT%%.cfg with the data from filter.template

Is it possible within m4 or I would need to write some scripting code?


Solution

  • define(`A_NODE',`myhostname')
    define(`A_NODE_PORT',`1234')
    syscmd(`cp filter.template filter_'A_NODE`_'A_NODE_PORT`.cfg')