awk if 1

awk if

# Basic syntax:
awk 'BEGIN {if(condition) outcome}' # if
awk 'BEGIN {if(condition_1) outcome_1; else outcome_2}' # if else
awk 'BEGIN {if(condition_1) outcome_1; else if(condition_2) outcome_2}' # if else if

# Example usage:
awk 'BEGIN {if(2>3) print "1_is_true"; else print 6}'
--> 6

# For multi-line and ternary operator syntax, see source

Here is what the above code is Doing:
1. The BEGIN block is executed before any input is read.
2. The condition is evaluated.
3. If the condition is true, the outcome is executed.
4. If the condition is false, the else outcome is executed.
5. The END block is executed after all input is read.

Similar Posts