Using awk or sed how can I select lines which are occurring between two different marker patterns? There may be multiple sections marked with these patterns but want only the last one to get printed.
For example: Suppose the file contains: abc def1 ghi1 jkl1 mno abc def2 ghi2 jkl2 mno pqr stu
And the starting pattern is abc and ending pattern is mno So, I need the output as:
def2 ghi2 jkl2
Not sure how to get this.
tac file | sed -n '/mno/,/abc/{/mno/d;/abc/q;p}' | tac
– Cyrus