Still struggling with messy logfiles. What I want is to find lines that first matching string X and then string Y. I then want to print them together. The problem is that, sometimes there is X, but no Y.
31 X 32 Y 33 X 34 Y 35 X 36 X 37 Y 38 X 39 X
31 X 32 Y 33 X 34 Y 36 X 37 Y
So, lines 35, 38 and 39 are omitted because there is no string Y.
My starting is point is this:
cat $filename | grep -E X\|Y | grep -A1 'X'
But this does not filter out lines 35, 38 and 39. What I want is a conditional: only print the lines X and then Y if there is Y. If not, print nothing.