With GNU grep(1)
grep -zoP "(?s)(?<=PAT1 )(.*)(?= PAT2)" file
Tests
$ cat file
Blalala
'Omfoem From
balanf PAT1 This is the
text that I want
to get PAT2: apples
Whatever: oranges
$ grep -zoP "(?s)(?<=PAT1 )(.*)(?= PAT2)" file
This is the
text that I want
to get
From grep(1) man page
-z, --null-data
Treat the input as a set of lines, each terminated by a zero byte (the ASCII NUL
character) instead of a newline. Like the -Z or --null option, this option can be
used with commands like sort -z to process arbitrary file names.
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part
on a separate output line.
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression (PCRE, see below). This is highly
experimental and grep -P may warn of unimplemented features.
Regex explanation:
(?s) activate PCRE_DOTALL, which means that . finds any character or newline.
Uses a Positive lookbehind assertion (?<=PAT1 ) and Positive lookahead assertion (?= PAT2) which causes to only print the capture group (.*).
Caveats of this solution:
As stated by @bushman this only works if there only exists in the file a single occurrence of the two patterns.
flag=1?