I needed to find all the files that contained a specific string pattern. The first solution that comes to mind is using find piped with xargs grep:
Why don't you go for awk:
awk '/Start pattern/,/End pattern/' filename
Here is a more useful example:
pcregrep -Mi "<title>(.*\n){0,5}</title>" afile.html
It searches the title tag in a html file even if it spans up to 5 lines.
Here is an example of unlimited lines:
pcregrep -Mi "(?s)<title>.*</title>" example.html
With silver searcher:
ag 'abc.*(\n|.)*efg'
Speed optimizations of silver searcher could possibly shine here.
You can use the grep alternative sift here (disclaimer: I am the author).
It support multiline matching and limiting the search to specific file types out of the box:
sift -m --files '*.py' 'YOUR_PATTERN'
(search all *.py files for the specified multiline regex pattern)
It is available for all major operating systems. Take a look at the samples page to see how it can be used to to extract multiline values from an XML file.
perl -ne 'print if (/begin pattern/../end pattern/)' filename
Here is the example using GNU grep:
grep -Pzo '_name.*\n.*_description'
-z
/--null-data
Treat input and output data as sequences of lines.
See also here