AWK help: how to compare array elements against a variable

i have an array call ignore. it is set up
ignore[0]=34th56
ignore[1]=re45ty
ignore[2]=rt45yu
.
.
ignore[n]=rthg34

n is a variable. I have another variable that i read from a different file. It is $2 and it is working the way i expect. array ignore read and print correct values.

in the below if statement (2nd if statement where i use array ignore), i need to do following, if "$2" == 34th56 || "$2" == re45ty || .... "$2" == rt45yu .i dont want to do a while or for loop, because it is printing lots of junk that i dont want. Can any one help me with this please? :frowning:

 
#! /usr/bin/ksh
# $2 is a variable and it is working the way i expect
# array ignore read and print correct values and it is working fine too
# in the if statement, i need to do following, if "$2" == ignore[0] || "$2" == ignore[1] || .... "$2" == ignore[n] 
#  { print "  " 
#   foundTermEvent = 0;
#   } 
#  else  {
#   print;
#   print " FOUND A BADTC  "  }

   file=../data/globallyIgnoredTc.dat
   set -A ignore `grep -v "#" ${file} | tr '[A-Z]' '[a-z]' `

 if (foundTermEvent == 1)
       {
          if ( "$2" in ignore )  
          {
      
                print " DIDNT FIND BAD TC "
        #       { print $1 }
        #       { print $2 }
                foundTermEvent = 0;
       
          }
            else
            {
            print;
            print " FOUND A BADTC  "
        #    { print $1 }
           { print $2 }
            print " ########################## "
           }
}

Ahem... you mentioned awk, but the script you provided seems to use ksh (line 1) while utilizing a mix of ksh- and awk-syntax. I'm not sure which environment you are actually using in your script.

If it is ksh: use "${arr[@]}", which puts the whole array into one string and use a grep of your input value to determine if it is part of it:

if [ $(print - "${ignore[@]}" | grep -c "$2") -gt 0 ] ; then
     print - "found $2 in array ignore[]"
else
    print - "did not find $2 in array ignore[]"
fi

I hope this helps.

bakunin

i am using AWK, and yes there is ksh too. but the part of the code i am working on is written in AWK.

i get a syntax error in below mention line. It doesnt seems to like red highlited brackets.
if [ $(print - "${ignore[@]}" | grep -c "$2") -gt 0 ] ; then