title: How to search with grep in files specified in a text file?
body: <p>I want to search with grep for a pattern in a number of files which I specified in a previous step and which are now stored in a text file.</p>
  
  <p>Lets say, in the first step, I used</p>
  
  <pre><code>grep -l 'pattern1' *.csv &gt;&gt; ~/filenames.txt 
  </code></pre>
  
  <p>to list the filenames of all the csv files which contained pattern1 and save these filenames into filenames.txt</p>
  
  <p>Now I would like to search all of the above files for a second pattern, pattern2.
  I'm looking for a command like</p>
  
  <pre><code>grep -?? 'pattern2' ~/filenames.txt
  </code></pre>
  
  <p>where -?? tells grep to look for filenames in filenames.txt
  I know that</p>
  
  <pre><code>grep -f patternfile.txt *.csv
  </code></pre>
  
  <p>Would search all csv files for the patterns defined in patternfile.txt. Is there an analog command for searching all files specified in a file full of filenames? </p>
  
  <p>I'm also happy to hear about alternative solution to my overall problem, e.g. somehow combining step 1 and 2 without the interim filenames.txt but it would also be interesting to know about the analog grep command, if it exists.</p>
  
  <p>To be clear, I am not just looking for files which contain pattern1 and pattern2. I'm interested in all occurrences for pattern2 (and then actually count them) in files in which pattern1 appears at least once.</p>