Using the m4 Macro Processor

By Paul Dunne, LinuxWorld.com |  Operating Systems Add a new comment

Chief among the the unsung heroes of Linux and Unix is m4. Unsung? Well, for
instance, although m4 has been a standard part of Unix since version 7,
no mention is made of it in that great O'Reilly & Associates book, Unix
Power Tools.
What is it
about m4 that makes it so useful, and yet so overlooked? m4 -- a macro
processor -- unfortunately has a dry name that disguises a great utility. A
macro processor is basically a program that scans text and looks for
defined symbols, which it replaces with other text or other symbols.
Thus, m4 is a powerful general-purpose utility that can be used to
automate many tasks people often end up doing in sed,
awk, perl, and
even their favorite text editor. Even so, it still doesn't seem like a macro
processor is that big of a deal.
Unix developers already have a built-in macro processor, in the form
of the C preprocessor, in their compiler. Perhaps this is
what accounts for m4's relative neglect. Whatever the case may be, this
article
will show Linux users the power and usefulness of this software tool.



What is m4?



What is macro processing, and what is it good for? In their seminal work,
Software Tools, Kernighan and Plauger have a succinct
definition:


"Macros are used to extend some underlying language -- to perform a
translation from one language to another."

    Add a comment

    Post a comment using one of these accounts
    Or join now
    At least 6 characters

    Note: Comment will appear soon after you have activated your account.
    Obscene/spam comments will be removed and accounts suspended.
    The information you submit is subject to our Privacy Policy and Terms of Service.

    ITworld LIVE

    Operating SystemsWhite Papers & Webcasts

    White Paper

    Microsoft Enterprise Agreement Program Overview

    Discover how flexible the Microsoft Enterprise Agreement Program is to help you build the right software solution agreement for your business. This paper highlights all the available options-from on-premise software and cloud service solutions, to payment options and enrollment programs, and more.

    White Paper

    Watson - A System Designed for Answers. The future of workload optimized systems design

    Watson is a workload optimized system designed for complex analytics, made possible by integrating massively parallel POWER7 processors and DeepQA technology. Read the white paper about Watson's workload optimized system design.

    See more White Papers | Webcasts

    Ask a question

    Ask a Question