title: Optimizing grep (or using AWK) in a shell script
body: <p>In my shell script, I am trying to search using terms found in a $sourcefile against the same $targetfile over and over.</p>
  
  <p>My $sourcefile is formatted as such:</p>
  
  <pre><code>pattern1
  pattern2
  etc...
  </code></pre>
  
  <p>The inefficient loop I have to search with is:</p>
  
  <pre><code>for line in $(&lt; $sourcefile);do
      fgrep $line $targetfile | fgrep "RID" &gt;&gt; $outputfile
  done
  </code></pre>
  
  <p>I understand it would be possible to improve this by either loading the whole $targetfile into memory, or perhaps by using AWK?</p>
  
  <p>Thanks</p>