The Citrine Citadel


Awkology

Posted 2024-06-29

I have successfully ported several nontrivial awk programs to work on quite a lot of real-world awk implementations. If I have learned anything from this process, it is that even though almost every system of interest has a POSIX-like “new awk” implementation, which is a great tool for writing portable scripts, there is quite a lot of variation in details. There is simply no substitute for real-world interoperability testing.

This article describes actual issues I have encountered, and suggests workarounds for each. Specific operating systems and versions are mentioned in examples for the aid of reproducing results. This indicates which systems I actually ran the examples on to demonstrate a particular implementation behaviour. It is not intended to suggest that a particular problem only occurs on that one particular OS version (even though that may indeed be the case).

For discussion of traditional (pre-POSIX “old awk”), the GNU Autoconf manual has a lot of details, but it is relatively sparse in its coverage of portability problems amongst POSIX “new awk” implementations.

Program Invocation

Modifying $0

Control Characters

Substituting Literal Backslashes

Function Definitions

Arbitrary Limits

Expression Evaluation

Regular Expressions

Particular Functions