In awk programming, the if statement is used for decision-making. The syntax is as follows:
if (conditional-expression) action1 else action2
If the condition is true, then action1 will be performed, else action2 will be performed. This is very similar to C programming if constructs.
An example of using the if statement in the awk command is as follows:
$ cat person.txt
The output is as follows:
Bill Thomas 8000 08/9/1968 Fred Martin 6500 22/7/1982 Julie Moore 4500 25/2/1978 Marie Jones 6000 05/8/1972 Tom Walker 7000 14/1/1977 $ awk '{ if ($3 > 7000) { print "person with salary more than 7000 is n", $1, " " , $2;} }' people.txt
The output is as follows:
person with salary more than 7000 is Bill Thomas ...