using arrays and also help with array.contains functionality

here is what i have...

i=1
while read line
do
     if grep -i-q "create procedure"<<<$line
     then
          startline="$line"
          endline="blahblah"
          Get procedure name into a variable named procName
           procName="procedure name is stored"
           do some stuff here so that one procedure from the tmp file is extracted and pasted to some other file
##now i want to perfrom below function using arrays
         if procName is present in arraylist then exit else continue
say like this
#   for j in $(seq 1 $i)
#   do
#        if [[ "$procName" == "$arraylist" ]]; then
#                 exit
#        fi
#   done
#but the exit should neglect below italised if statements but it should go to while loop again.. that is it should'nt exit from while loop. 
i thought of using for loop to check it like above i dont know whether this will work or not.. since i will be perfroming a large file it will consume a lot of time to test so 
can anyone plz let me know what will work for my case plz.. 
              if this procedure is present in second file say tmp2.sql then
                do some stuff here
                take the procedure name and store it in a variable..
                  arraylist=$procName
                 i=`expr i + 1`
               delete the procedure from the second file that is tmp2.sql
since some stuff are perfromed using it and no longer needed
            fi
   fi
 
 
 
done < tmp.sql
 

---------- Post updated at 05:53 PM ---------- Previous update was at 05:01 PM ----------

okay i somehow made this workaround .....is there any one line code for this...such that its output will be 1 if present else 0

for j in $(seq 1 $i)
do
        if [[ "$proc_name1" == "${arraylist[j]}" ]]; then
                flag=1
        fi
done

Instead of exit, you can use continue to continue from the beginning of the while loop.

Fro searching the array, you can probably do something like this instead of a for loop

grep $proc_name1 <<< ${arraylist
[*]}

#or

echo ${arraylist
[*]} | grep $proc_name1

HTH
--ahamed

1 Like

@ahamed.. thanks a lot your code worked for me :slight_smile: