This is a script called m5.awk that I randomly found after reading a paper about it on the ACM website. The paper’s worth reading too but the script is just a piece of work. Commented to the brim, clean, and most importantly, useful as hell. it could be a replacement for m4. It allows you to embed AWK in text files, and besides that, it allows you to use several preprocessng features that it offers via macros. Give it a try.
Languages like C have a preprocessor. The preprocessor preprocesses the source code before compiling it. The C preprocessor, copy-pastes code from other files into the current file (
#include
s), erases code (#if
if the condition is false), and expands macros (e.g. you have#define MAX(x, y) ((x) < (y) ? (y) : (x))
, it replaces every use of that macro with the definition of that macro:a += a * MAX(b, c)
→a += a * ((b) < (c) ? (c) : (b))
. There are also general-purpose preprocessors (or macro processors), that are not tied to a specific programming language however. m4 is one of them and GNU autotools make extensive use of them to generate their configuration and make files. What preprocessors allow one to do is write a template, and then generate a result, based on your needs.