Decision-making using an if statement

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 ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.