how to find last occurrence of a pattern file 1

how to find last occurrence of a pattern file

tac < fileName | sed  '/EndPattern/,$!d;/StartPattern/q' | tac 

Here is what the above code is Doing:
1. tac is used to reverse the file.
2. sed is used to print the lines between StartPattern and EndPattern.
3. tac is used to reverse the output of sed.

Similar Posts