title: Include header in the 'grep' result
body: <p>Is there a way to combine 'head -1' and 'grep' command into one for all the files in a directory and redirect the output to an output file. I can do this using 'sed' but it seems that it is not as fast as grep.   </p>
  
  <pre><code>sed -n '1p;/6330162/p' infile*.txt &gt; outfile.txt
  </code></pre>
  
  <p>Using grep I can do the following one file at a time:</p>
  
  <pre><code>head -1 infile1.txt;  grep -i '6330162' infile1.txt &gt; outfile.txt
  </code></pre>
  
  <p>However, I need to do it for all files in the directory. Inserting a wildcard is not helping as it is printing headers first and then the grep output.</p>