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
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs