Why does awk "not in" array work just like awk "in" array?

In my solution for this problem I use the following if-else statement:

if($1 in contained);else{print "Here goes your code for \"not in\""}

I figured this one out. The ( x in array ) returns a value, so to do "not in array", you have to do this:

if ( x in array == 0 )
   print "x is not in the array"

or in your example:

($1 in Contained == 0){
   print $0
}

I cannot find any doc about element not in array.

Try !(element in array).


I guess: awk sees not as an uninitialized variable, so not is evaluated as an empty string.

$1 not == $1 "" == $1

Tags:

Awk

Gawk