title: Awk printing matched line and Nth following line using c&&!--c
body: <p>So, I have got my head around the famous "c&amp;&amp;!--c".. Although maybe not.</p>
  
  <p>When using Awk to print the Nth line after a matched line, I'd like to print the Nth line, a space, then the matched line, on the same output line.</p>
  
  <p>For example, given the file tmpfile.txt;</p>
  
  <pre><code>blar
  Matchme
  blar
  XXXX
  blar
  </code></pre>
  
  <p>I'd like to get the following</p>
  
  <pre><code>XXXX Matchme
  </code></pre>
  
  <p>But.. Using </p>
  
  <p><code>awk 'c&amp;&amp;!--c  ; /Matchme/ {c=2} ; /Matchme/' tmpfile.txt</code></p>
  
  <p>gives</p>
  
  <pre><code>Matchme
  XXXX
  </code></pre>
  
  <p>Adding a printf doesn't help.. </p>
  
  <p><code>awk 'c&amp;&amp;!--c  ; /Matchme/ {c=2} ; /Matchme/ {printf $0}' tmpfile.txt</code></p>
  
  <p>gives</p>
  
  <pre><code>MatchmeXXXX
  </code></pre>
  
  <p>Can anyone explain why the first pattern/action is being printed last?</p>
  
  <p>Thanks</p>
  
  <p>gary_s</p>