title: Print line that meets conditions in different lines with awk
body: <p>total newbie. It is possible with awk to print the following:</p>
  <pre><code>w171930 t1 Y z2545377 &lt;--- print this line
  w171930 t2 X z4495648
  w171931 t1 Y z2555698 &lt;--- print this line
  w171931 t2 X z5505690
  w171932 t1 Y z2554345 &lt;--- print this line
  w171932 t2 X z5507345
  w171933 t1 Y z2214694
  w171933 t2 Y z8022710
  w171933 t3 Y z2143462
  w171933 t4 Y z6217556
  w171933 t5 Y z9608343
  w171933 t6 Y z9984446
  w171933 t7 Y z2985572
  w171933 t8 Y z6334512 &lt;--- print this line
  w171933 t9 X z6503375
  w171943 t1 Y z2441603 &lt;--- NO print this line
  w171943 t2 X z4644534
  w171943 t3 Y z2164440
  w171944 t1 Y z2165532
  </code></pre>
  <p><strong>Search on $3 == &quot;X&quot; and print the previous line if the next line has a $2 == &quot;t1&quot;</strong></p>
  <p><strong>Goal</strong></p>
  <pre><code>w171930 t1 Y z2545377
  w171931 t1 Y z2555698
  w171932 t1 Y z2554345
  w171933 t8 Y z6334512
  </code></pre>
  <p>I have only managed to print the previous line but I don't know how to perform the complete condition</p>
  <pre><code>awk '$3 == &quot;Y&quot; { Y=$0; next; } { if ($3 ==&quot;X&quot;) print Y;}'
  </code></pre>
  <p>I'm sorry if I don't express myself correctly</p>
  <p><a href="https://i.stack.imgur.com/Y8AkO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y8AkO.png" alt="enter image description here" /></a></p>