2.0 The AWK Ecosystem: Variants and Environment Setup
2.1 Understanding AWK Variants
While AWK refers to a single language specification, several implementations have been developed over the years. Understanding these variants is important, as the specific version available can determine which features are supported. Modern systems, particularly GNU/Linux distributions, have standardized on a powerful and backward-compatible version.
The three main variants of the language are:
AWK: The original version developed at AT&T Laboratory. NAWK: A newer, improved version of the language, also from AT&T Laboratory. GAWK: The GNU implementation of AWK. It is the standard version shipped with all GNU/Linux distributions and is fully compatible with both the original AWK and NAWK specifications, while also adding its own extensions.
2.2 Verifying and Installing AWK
AWK is generally available by default on most GNU/Linux distributions. Installation, if needed, can be handled through two primary methods: using a system’s package manager or compiling the language from its source code.
Installation Using a Package Manager
Before attempting an installation, you can verify if AWK is already present on your system by using the which command.
[jerry]$ which awk
/usr/bin/awk
If the command returns a path, AWK is installed. If not, you can install it using the appropriate package manager for your distribution.
- On Debian-based systems (like Ubuntu), use apt-get:
- On RPM-based systems (like Fedora or CentOS), use yum:
Installation from Source Code
For users who require the latest version or a custom build, GAWK can be compiled and installed directly from its source code.
- Download the source code. The wget utility can be used to download the source archive from the official GNU repository.
- Decompress and extract the archive.
- Configure the build. Navigate into the newly created directory and run the configure script, which prepares the source for compilation on your system.
- Compile the source code. The make command uses the Makefile generated by configure to build the executable.
- Run tests (optional). This step runs a test suite to ensure the build is clean and functioning correctly.
- Install the program. This command copies the compiled files to the appropriate system directories. Super-user privileges are required.
With the environment successfully configured, the next step is to understand the fundamental model AWK uses to process data.