How to show lines after each grep match until other specific match?

It seems that you want to print lines between 'Word A' and 'Word D' (inclusive). I suggest you to use sed instead of grep. It lets you to edit a range of input stream which starts and ends with patterns you want. You should just tell sed to print all lines in range and no other lines:

sed -n -e '/Word A/,/Word D/ p' file

why not use awk ?

awk '/Word A/,/Word D/' filename

perl -lne 'print if /Word A/ .. /Word D/' file

or

cat file | perl -lne 'print if /Word A/ .. /Word D/'

Tags:

Grep