gargamel100
Technical User
Hi all,
using code bellow I want to check if $21=="1" and $9=="2222". If this is true then print 2222, and value for a.
awk -F"|" '
$21 == "1" && $9 == "2222" {a=a+1}
END {print " 2222 ", a}'
But in some cases a is equal 0 and in that case
END {print " 2222 ", a} will print just 2222, like
2222
but I wish in this case (when a is zero) to print zero and got output like
2222 0
and so on.
I tried make this using
END {print " 2222 ", if (a==0) print a else print "0"}
but I got an error like
syntax error at or near if
I really do not know what I made wrong in this case, and if someone can see my mistake, please write it down.
Regards
Gargamel100
using code bellow I want to check if $21=="1" and $9=="2222". If this is true then print 2222, and value for a.
awk -F"|" '
$21 == "1" && $9 == "2222" {a=a+1}
END {print " 2222 ", a}'
But in some cases a is equal 0 and in that case
END {print " 2222 ", a} will print just 2222, like
2222
but I wish in this case (when a is zero) to print zero and got output like
2222 0
and so on.
I tried make this using
END {print " 2222 ", if (a==0) print a else print "0"}
but I got an error like
syntax error at or near if
I really do not know what I made wrong in this case, and if someone can see my mistake, please write it down.
Regards
Gargamel100