Introduction – AWK Tutorial
AWK is not a fully-featured scripting language, but it is a Linux/UNIX based powerful text processing and text data extraction tool. It is a very powerful text-processing language that’s why it works mostly on string data types. However, it can process associative arrays and most of the regular expression, for example, arithmetic, conditional, looping, etc. In this AWK tutorial, we will learn the most basic syntax of AWK and then we will learn how to work with AWK actually.
AWK was developed at Bell labs before the development of the C programming language in 1970. The main uses of AWK in Unix and Linux based operating system is to print out formatted text-based data by reading a predefined file that is written by following awk format. Moreover, you can use AWK on different OS. Because AWK is a cross-platform scripting language.
Using AWK you can do:
- Working with variables
- Logical control flow
- Repetition using loop
- Finally using logic you can print out formatted reports
AWK Versions and Variations
AWK is the eldest version. Two major refined versions of AWK has been released. But the AWK is still in used interactively than the other two versions because of its simplicity and efficiency. The versions of AWK are:
- AWK – the (very old) original by AT&T [Ooldest but still in use]
- NAWK – A newer, improved version of AWK by AT&T
- GAWK – The Free Software foundation’s version
In this tutorial, we will learn the most used or oldest version of AWK. But you can migrate anytime to the other two versions. AWK or AWK commands are base to learn actually.
AWK Program Structure and Procedure
You can program with AWK in several ways. You can either write a bunch of AWK commands or expressions to be executed sequentially or you can program in the shell by entering the single command you want to execute. There are lots of AWK command you can use to manipulate the text data. In the next subsequent chapters, we will learn them. So, let’s start!