title: Grep to multiple output files
body: <p>I have one huge file (over 6GB) and about 1000 patterns. I want extract lines matching each of the pattern to separate file. For example my patterns are:</p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>my file:</p>
  
  <pre><code>a|1
  b|2
  c|3
  d|123
  </code></pre>
  
  <p>As a output I would like to have 2 files:</p>
  
  <p>1:</p>
  
  <pre><code>a|1
  d|123
  </code></pre>
  
  <p>2:</p>
  
  <pre><code>b|2
  d|123
  </code></pre>
  
  <p>I can do it by greping file multiple times, but it is inefficient for 1000 patterns and huge file. I also tried something like this:</p>
  
  <pre><code>grep -f pattern_file huge_file
  </code></pre>
  
  <p>but it will make only 1 output file. I can't sort my huge file  - it takes to much time. Maybe AWK will make it? </p>