O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

If...else

In an if...else statement, we can specify a list of actions to be performed if the conditional expression becomes false. The syntax of if...else is as follows:

if ( conditional-expression )

action1

else

action2

If conditional-expression evaluates to true (nonzero), then action1 is performed, and if conditional-expression evaluates to false (zero), then action2 is performed, as shown in the following figure:

Figure 7.2: An if...else statement flowchart

AWK also has a conditional ternary operator (? :); it is equivalent to the one in C language. It is the same as an if...else statement. The syntax of the ternary operator is as follows: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required