title: How to find files in UNIX which have a multiple-line pattern?
body: <p>I'm trying to search all files for a pattern that spans multiple lines, and then return a list of file names that match the pattern.</p>
  
  <p>I'm using this line:</p>
  
  <pre><code>find . -name "$file_to_check" 2&gt;/dir1/null | xargs grep "$2" &gt;&gt; $grep_out
  </code></pre>
  
  <p>This will create a list of files and the line the matched pattern is found on within $grep_out. The problem with this is that the search doesn't span multiple lines. I've read that grep cannot span multiple lines, so I'm looking to replace grep with sed or awk.</p>
  
  <p>The only thing I think that needs to be changed is the grep. I've found that grep can't search for a pattern across multiple lines, so I'm looking to use sed or awk. When I use these commands from the terminal, I get a large printout of the file matching the pattern I've given sed. All I want is the filename, not the context of the pattern. Is there a way to retrieve this - perhaps have sed print out the filename rather than the context? Or, have sed return true/false when it finds a match, and then I can save the current filename that was used to do the search.</p>