The ---
are easily repeatable and easily to "catch". Accumulate blocks separated by ---
into hold space, then match the whole hold space with the searched pattern. If it does not match, print it.
The following shell script:
cat <<EOF |
---
some text
more text
MATCH: FIRST
more text
---
some text
more text
---
some text
MATCH: SECOND
more text
---
some
more
MATCH: THIRD
text
here
---
moretest
---
andnaotherone
---
MATCH: SECOND
---
MATCH: SECOND
---
EOF
sed -n '
/^---$/!{H;b} # Accumulate one block
H;x;
# If there is the searched pattern
/
MATCH: (FIRST|SECOND)
/!{
s/^
// # the leading newline from H
p
} ; : OKEY
# Clear hold space so its empty
s/.*//;h
b
'
outputs:
---
some text
more text
---
some
more
MATCH: THIRD
text
here
---
moretest
---
andnaotherone
---
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…