about awk code
awk '/string1/ {if ( c <= 0 ) c = 1;} /string2/ {c=5} { if (c-- > 0) print; }' file
- do not
cat ... | awk
, awk can read file. - I rearrange test (if string1 is one line after string2, it interrupt printing in OP's solution)
about awk code
awk '/string1/ {if ( c <= 0 ) c = 1;} /string2/ {c=5} { if (c-- > 0) print; }' file
cat ... | awk
, awk can read file.