7.1. awk¶
AWK is a command line utility to filter text. It can be used for various purposes. One of the most important use case is when its intput piped from some othe process.
It can be tremendously helpful in many scripting tasks.
Let’s se some of the powers of AWK. Imagine, we have a text file like below. It just shows name of people and their marks.
Name Marks
Purnank 89
Meera 92
Dehlia 90
Ved 91
Who got more than 90 marks?
awk '$2 > 90 {print $0}' sample_awk.txt
Name Marks
Meera 92
Ved 91
Same question. Who got more than 90 marks? But print little better.
awk '$2 > 90 {print $1,"\t",$2}' sample_awk.txt
Name Marks
Meera 92
Ved 91
Find which lines are more than 8 characters wide.
awk 'length($0) > 8 {print $0}' sample_awk.txt
Name Marks
Purnank 89
Dehlia 90
7.1.1. Further Reading¶
The goal of this book/document is not to make you and expert at AWK, but just to give you a glimpse as to what is basically possible with AWK. You must be now aware, of the utility AWK and think about using it for post processing some file our output to check some summary as a part of your scripts.