Print all lines before nth occurrence of a string (e.g stop print lines when 'bbo' appears 7 times)

awk -v N=7 '{print}/bbo/&& --N<=0 {exit}'
click the source code to copy