title: Awk - print next record following matched record
body: <p>I'm trying to get a next field after matching field using awk.</p>
  
  <p>Is there an option to do that or do I need to scan the record into array then check each field in array and print the one after that?</p>
  
  <p>What I have so far:</p>
  
  <p>The file format is:</p>
  
  <pre><code>&lt;FIELD&gt;&lt;separator "1"&gt;&lt;VALUE&gt;&lt;separator "1"&gt;&lt;FIELD&gt;&lt;separator "1"&gt;&lt;VALUE&gt; 
  </code></pre>
  
  <p>... and so on, <code>field|value</code> pairs are repeated, will be at least one pair in line or multiple pairs &lt;10 per line</p>
  
  <p>dat.txt:</p>
  
  <pre><code>FIELDA01VALUEA01FIELDA21VALUEA21FIELDA31VALUEA3
  FIELDB01VALUEB01FIELDB21VALUEB21FIELDB31VALUEB3
  FIELDC01VALUEC01FIELDC21VALUEC21FIELDC31VALUEC3
  FIELDD01VALUED01FIELDD21VALUED21FIELDD31VALUED3
  FIELDE01VALUEE01FIELDE21VALUEE21FIELDE31VALUEE3
  </code></pre>
  
  <p>With simple awk script which prints the second field on a line matching FIELDB2:</p>
  
  <pre><code>#!/bin/awk -f
  
  BEGIN { FS = "1" }
  /FIELDB2/ { print $2 }
  </code></pre>
  
  <p>Running the above:</p>
  
  <pre><code>&gt; ./scrpt.awk dat.txt
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre><code>VALUEB0
  </code></pre>
  
  <p>This is because the line that match:</p>
  
  <pre><code>FIELDB01VALUEB01FIELDB21VALUEB21FIELDB31VALUEB3
  </code></pre>
  
  <p>When split into records looks:</p>
  
  <pre><code>FIELDB0 VALUEB0 FIELDB2 VALUEB2 FIELDB3 VALUEB3
  </code></pre>
  
  <p>From which the second field is <code>VALUEB0</code></p>
  
  <p>Now I don't know which <code>FIELDXX</code> will match but I would like to print the next record on the line after <code>FIELDXX</code> that matched, in this specific example when <code>FIELDB2</code> matches I need to print <code>VALUEB2</code>.</p>
  
  <p>Any suggestions?</p>