title: Print the next column after a match in gawk
body: <p>I have a large file with multiple lines of text and columns, I have put a sample set below, the file comes from a windows server and the gawk is being run on windows fro  within DOS.</p>
  
  <pre><code>170228 000005 0499 DE(N) SortationHandler.sortationio.Comm Sending Telegram: &lt;ItemEvent&gt;&lt;312285164&gt;&lt;25243153&gt;&lt;EXTERNAL_REDIRECTED&gt;&lt;2017-02-28 00:00:05.062+0300&gt;&lt;1&gt;&lt;&gt;&lt;0157368350&gt;&lt;previousScans&gt;&lt;0&gt;&lt;2&gt;&lt;position&gt;&lt;sorter#0&gt;&lt;destinations&gt;&lt;2&gt;&lt;=TT1-CHU013&gt;&lt;=TT1-CHU081&gt;&lt;36&gt;
  170228 000005 0499 DE(N) SortationHandler.sortationio.Comm Sending Telegram: &lt;ItemEvent&gt;&lt;312285166&gt;&lt;25243152&gt;&lt;INDUCTED&gt;&lt;2017-02-28 00:00:05.437+0300&gt;&lt;1&gt;&lt;&gt;&lt;0157370126&gt;&lt;previousScans&gt;&lt;0&gt;&lt;1&gt;&lt;position&gt;&lt;sorter#0&gt;&lt;36&gt;&lt;screenedSufficiently&gt;
  </code></pre>
  
  <p>I want to be able to search for a specific string such as <code>&lt;passengerName&gt;</code> and then print out the <strong>next</strong> column and then add 3 or 4  other columns into the file output, I will always want the date and time at the start.</p>
  
  <p>The issue is that the field position can change and is not static other than the date and time.</p>
  
  <p>I have tried various gawk commands but nothing I try or have searched for gives me what I need.</p>
  
  <pre><code>gawk -F'[&lt;&gt;]''{for(i=1;i&lt;=NF;i++)if($i=="&lt;passengerName&gt;")print$(i+1)}'
  </code></pre>
  
  <p>I would also like to output in a comma delimited file and remove the &lt;> from around the columns</p>
  
  <p>What I would like is an output something like the one below where I can pick the columns I need seperated by a comma</p>
  
  <pre><code>170228 000005,1FARHANA/MRS,QR118,QR
  </code></pre>
  
  <p>Any help would be appreciated</p>