I have a file that has the following pattern.
A
.
.
XYZ
.
.
A
.
.
A
.
.
A
.
.
XYZ
where "."s are new lines with random words (not A or XYZ).
I want to count all the occurrences of patterns that match
A
. (any number of lines)
XYZ
I also want to count it only when A is followed by XYZ and not when A is followed by another A.
I tried
pcregrep -Mc 'A.*(\n?|.)*?XYZ' file.txt
but it fails with
> pcregrep: pcre_exec() gave error -27 while matching text that starts:
Desired output for the above input: 2
Does anyone have any idea how to do this?