Awk is a versatile programming language designed for pattern scanning and processing language and often used as a data extraction and reporting tool. It’s an excellent filter and report writer. It’s a standard feature of most Unix-like operating systems.
Awk is small, fast, simple, and has a clean comprehensible C-like input language. It has robust programming constructs including if/else, while, do/while and for C-style and array iteration.
The name awk comes from the initials of its designers: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan. The original version of awk was written in 1977 at AT&T Bell Laboratories.
The language is suited for:
- Tallying information from text files and creating reports from the results.
- Adding additional functions to text editors like “vi”.
- Translating files from one format to another.
- Creating small databases.
- Performing mathematical operations on files of numeric data.
There’s a limited range of good free books to learn about programming in Awk. Here’s my recommended texts.
1. GAWK: Effective AWK Programming Edition 5.0 by Arnold D. Robbins
This practical guide serves as both a reference and tutorial for POSIX-standard awk and for the GNU implementation, called gawk. This book is useful for novices and awk experts alike.
GAWK: Effective AWK Programming explains both how to write programs in the awk language and how to run the awk utility. The term “awk program” refers to software written in the awk programming language.
The book serves as both a tutorial and reference guide. The first part of the book describes the awk language and the gawk program in detail. The second part of the book shows you how to use awk and gawk to solve problems. The third part concentrates on features specific to gawk. The final part of the book provides appendices, and a useful Glossary. There’s a wealth of information in the book.
Read the 5th edition in PDF format at https://www.gnu.org/software/gawk/manual/gawk.pdf.
Permission is granted to copy, distribute and/or modify GAWK: Effective AWK Programming Edition under the terms of the GNU Free Documentation License, Version 1.3.
The book’s cover relates to the 4th edition published by O’Reilly.
2. Awk Tutorial by Bruce Barnett
Awk Tutorial discusses Awk, a cornerstone of UNIX shell programming.
- Executing an Awk script.
- Which shell to use with Awk?
- Dynamic Variables.
- Arithmetic Expressions.
- Summary of Awk Commands.
- Awk Built-in Variables: FS, OFS, NF, NR, RS, ORS, and FILENAME.
- Associative Arrays.
- Picture Perfect PRINTF Output.
- Flow Control with next and exit.
- Awk Numerical Functions.
- String Functions.
- User Defined Functions.
- Awk patterns.
- Formatting Awk programs.
Read the tutorial at https://www.grymoire.com/Unix/Awk.html.
3. An Awk Primer by Wikibooks
An Awk Primer is a useful guide which explains Awk’s syntax in some depth covering search patterns, numbers and strings, variables, arrays, operations, standard functions, user-defined functions, control structures, and more.
There’s also some example Awk program files, and a quick reference guide.
Permission is granted to copy, distribute, and/or modify An Awk Primer under the terms of the Creative Commons Attribution-ShareAlike 3.0 License.
All books in this series:
|Free Programming Books|
|Java||General-purpose, concurrent, class-based, object-oriented, high-level language|
|C||General-purpose, procedural, portable, high-level language|
|Python||General-purpose, structured, powerful language|
|C++||General-purpose, portable, free-form, multi-paradigm language|
|C#||Combines the power and flexibility of C++ with the simplicity of Visual Basic|
|PHP||PHP has been at the helm of the web for many years|
|HTML||HyperText Markup Language|
|SQL||Access and manipulate data held in a relational database management system|
|Ruby||General purpose, scripting, structured, flexible, fully object-oriented language|
|Assembly||As close to writing machine code without writing in pure hexadecimal|
|Swift||Powerful and intuitive general-purpose programming language|
|Groovy||Powerful, optionally typed and dynamic language|
|Go||Compiled, statically typed programming language|
|Pascal||Imperative and procedural language designed in the late 1960s|
|Perl||High-level, general-purpose, interpreted, scripting, dynamic language|
|R||De facto standard among statisticians and data analysts|
|COBOL||Common Business-Oriented Language|
|Scala||Modern, object-functional, multi-paradigm, Java-based language|
|Fortran||The first high-level language, using the first compiler|
|Scratch||Visual programming language designed for 8-16 year-old children|
|Lua||Designed as an embeddable scripting language|
|Logo||Dialect of Lisp that features interactivity, modularity, extensibility|
|Rust||Ideal for systems, embedded, and other performance critical code|
|Lisp||Unique features - excellent to study programming constructs|
|Ada||ALGOL-like programming language, extended from Pascal and other languages|
|Haskell||Standardized, general-purpose, polymorphically, statically typed language|
|Scheme||A general-purpose, functional language descended from Lisp and Algol|
|Prolog||A general purpose, declarative, logic programming language|
|Forth||Imperative stack-based programming language|
|Clojure||Dialect of the Lisp programming language|
|Julia||High-level, high-performance language for technical computing|
|Awk||Versatile language designed for pattern scanning and processing language|
|BASIC||Beginner’s All-purpose Symbolic Instruction Code|
|Erlang||General-purpose, concurrent, declarative, functional language|
|VimL||Powerful scripting language of the Vim editor|
|OCaml||The main implementation of the Caml language|
|ECMAScript||Best known as the language embedded in web browsers|
|Bash||Shell and command language; popular both as a shell and a scripting language|
|LaTeX||Professional document preparation system and document markup language|
|TeX||Markup and programming language - create professional quality typeset text|
|Arduino||Inexpensive, flexible, open source microcontroller platform|
|Elixir||Relatively new functional language running on the Erlang virtual machine|
|F#||Uses functional, imperative, and object-oriented programming methods|
|Tcl||Dynamic language based on concepts of Lisp, C, and Unix shells|
|Factor||Dynamic stack-based programming language|
|Eiffel||Object-oriented language designed by Bertrand Meyer|
|Agda||Dependently typed functional language based on intuitionistic Type Theory|
|Icon||Wide variety of features for processing and presenting symbolic data|
|XML||Rules for defining semantic tags describing structure ad meaning|
|Vala||Object-oriented language, syntactically similar to C#|
|Standard ML||General-purpose functional language characterized as "Lisp with types"|
|D||General-purpose systems programming language with a C-like syntax|
|Dart||Client-optimized language for fast apps on multiple platforms|
|Markdown||Plain text formatting syntax designed to be easy-to-read and easy-to-write|
|Kotlin||More modern version of Java|
|Objective-C||Object-oriented language that adds Smalltalk-style messaging to C|
|VHDL||Hardware description language used in electronic design automation|
|J||Array programming language based primarily on APL|
|LabVIEW||Designed to enable domain experts to build power systems quickly|
|PostScript||Interpreted, stack-based and Turing complete language|
|Raku||Member of the Perl family of programming languages|