2

Tip #490   Simple Templates with m4

The m4 command is designed specifically for macro processing. m4 manipulates files, performs arithmetic, has functions for handling strings, and can do much more.

Here's a quick example of using m4 with templates:
$ cat temp
The COLOR fox jumped over the TYPE dog.


Were you to substitute the strings 'COLOR' by 'brown' and 'TYPE' by 'lazy', you could use:
$ m4 -DCOLOR=brown -DTYPE=lazy temp
The brown fox jumped over the lazy dog.


Else, if you want to substitute 'white' and 'big' for the same:
$ m4 -DCOLOR=white -DTYPE=big temp
The white fox jumped over the big dog.

 
  • TAGS:
  • m4