Start_pattern
abc
d End_pattern
Start_pattern
abc
d
ef
ghij
klm
no End_pattern
Start_pattern
abc
def
hij End_pattern
Start_pattern
abc
dhi
jklm End_pattern
adapting from my answer on another site - Get text between start pattern and end pattern based on pattern between start and end pattern
$ awk '/Start_pattern/{f=1; m=0; buf = $0; next}
/ef/ && f{m=1}
f{buf = buf ORS $0}
/End_pattern/ && f{f=0; if(m==1)print buf}
' ip.txt
Start_pattern
abc
d
ef
ghij
klm
no End_pattern
Start_pattern
abc
def
hij End_pattern
/Start_pattern/{f=1; m=0; buf = $0; next} set flag to indicate start of block, clear match, initialize buffer and move on to next line/ef/ && f{m=1} if line contains ef, set match. f is used to avoid matching ef outside of Start_pattern...End_patternf{buf = buf ORS $0} as long as flag is set, accumulate input lines/End_pattern/ && f{f=0; if(m==1)print buf} at end of block, print buffer if match was found