In this article we will see when if block is true or false in without operator scenario. Means none of the following is used.
-eq/-ne/-lt/-gt/=/==/!=
echo "" | awk 'BEGIN{V_Count=0}-eq/-ne/-lt/-gt/=/==/!=
{ if (V_Count)
{
print "TRUE"
}
else
{
print "FALSE"
}
}'
Output: In above scenario, we have initialized a variable V_Count and assigned the value as 0. if inside awk command considered 0 as FALSE hence displayed FALSE on terminal.
$ echo "" | awk 'BEGIN{V_Count=1}
{ if (V_Count)
{
print "TRUE"
}
else
{
print "FALSE"
}
}'
[OR]
$ echo "" | awk 'BEGIN{V_Count=2}
{ if (V_Count)
{
print "TRUE"
}
else
{
print "FALSE"
}
}'
Output: In above scenario, we have initialized a variable V_Count and assigned the value as 1 and 2 in next example. if inside awk command considered non-zero value as TRUE hence displayed TRUE on terminal for both the cases.
Note: This is very important concept of awk command and is used extensively. Keep the concept handy for complex code understanding.
No comments:
Post a Comment