How to keep rows containing pattern 1 only if the next line contains pattern 2 and starts with pattern 3 ?
Exemple: keep line starting with an A only if the next line starts with a B and contains the pattern B1
Input file
A item1A
B item1B2
A item2A
A item3A
B item3B1
B item3CB1
B item3B2
A item5A
B item5B1
A item6A
Expected output:
A item3A
B item3B1
B item3CB1
A item5A
B item5B1
( I'm currently trying with grep -e ^A -e B1 but the side effect is that all A s lines are kept )
A.