linux grep get lines above and below code example
Example 1: grep show lines above and below
grep -C 3 foo README.txt
Example 2: grep show lines between matches
Just use following structure to get result between two different patterns:
sed -n '/^pattern1/,/^pattern2/p;/^pattern2/q' file.txt