title: Grep for each element of array in a loop and write to newfile with BASH
body: <p>I am using grep and a for loop to try and search for each element of an array (ids) in a file (4700921_combined_subs.txt) and then write each line to a new file which is named as the search term.  There are multiple occurances of each search term in the file being searched.</p>
  
  <p>Can someone help me decipher what is wrong with my code? It does everything i want except the resultant files are all empty. any ideas?</p>
  
  <pre><code>    for i in "${ids[@]}"
          do 
          grep '^$i' 4700921_combined_subs.txt &gt; $i.txt
          done
  </code></pre>
  
  <p>Many thanks in advance</p>