title: search through a file with list of elements in an array using shell
body: <p>I have a list of elements in an array (eg. xml tags) and if I were to search them through a list of files and extract matching lines to a temp file.What is a good way?</p>
  
  <p>here's what I tried in a script:</p>
  
  <pre><code>myArray =(ZZ1 BZ1 ZZ2 AZ1 AZ2)
  
  echo "${myArray[@]}"
  
  while read line
  do
   if [[ "$line" =~ ${myArray[@]} ]];then
         echo $line | awk -F "[&gt;&lt;]" '{print $2"|"$3}'
  fi
  done &lt; file.xml
  </code></pre>
  
  <p>Thanks all for the information:</p>
  
  <p>But the below comparison -- "$line" =~ $regex is scanning through the file and fetching all the data along with the data that im looking.how to filter them?</p>