Learn the Linux Command - gawk

Use 'gawk' or 'awk' to manipulate text files

The Linux program gawk is a GNU implementation of the awk programming language. Use gawk to change text files based on patterns instead of writing complex scripts in other languages to accomplish the same task.

Depending on your distribution, gawk may not be installed by default—either use awk or install it from your distribution's software repository.

What 'gawk' Does

In a nutshell, awk and gawk instructs your shell to perform a series of commands against text files. Those commands relate to the modification or extraction of specific parts of a text document.

The language is straightforward but detailed. Refer to the online manual for complete usage notes and syntax.

The gawk utility is functionally equivalent to awk. In 1977 the original awk released; in 1988, gawk released, which expanded on the original in the spirit of the GNU project for free and open-source software.

Example Usage

A typical use of gawk uses a defined program against one or more input files. The paradigm looks something like this:

gawk program file1 file2 ...

In this case, program references a specific script that performs a specific function that applies to file1, file2, etc.

Usually, the program is a simple script that scans each line of file1 looking for a pattern and when it finds it, it executes a command. The output generally prints to standard output unless programmatically redirected or piped to a new file.