SyntaxFix
Write A Post
Hire A Developer
Questions
A belated post: Use the search regex pattern as a Record Separator (RS) in awk This allows your regex to span \n-delimited lines (if you need it).
awk
\n
printf 'X \n moo X\n XX\n' | awk -vRS='X[^X]*X' 'END{print (NR<2?0:NR-1)}'