0

First it should grep for Pattern_A, then print all lines before Pattern_A until Pattern_B is found(so basically it should search backwards)

line1 line2 line3 line4 Pattern_B line5 line6 line7 line8 Pattern_A line9 line10 line11 Pattern_B line12 line13 line14 line15 Pattern_A line16 line17 .... .... ....

I want the output to be like this:

Pattern_B line5 line6 line7 line8 Pattern_A Pattern_B line12 line13 line14 line15 Pattern_A

Nani
  • 353

1 Answers1

0

Whenever I hear "do something backwards", I think: reverse the input then do that something "normally", then reverse the results:

tac file | sed -n '/Pattern_A/,/Pattern_B/p' | tac

However in this case, the same results occur from "search from pattern B to pattern A"

sed -n '/Pattern_B/,/Pattern_A/p' file
glenn jackman
  • 85,964