title: awk to print part of an array in shell
body: <p>Hello I have a text file with hundreds of lines. Here's a sample. </p>
  
  <pre><code>Array 1 - JVMAZURE,/www/deploy/DEV/JVMAZURE/ReceiveResponseFromAzureDEV,com.azure.ReceiveResponseFromAzure
  
  JVM - JVMAZURE
  Node - com.azure.ReceiveResponseFromAzure
  Jar - /www/deploy/DEV/JVMAZURE/ReceiveResponseFromAzureDEV
  AXIOM.SVAP.IN
  LOG.XML.INPUT
  SERVADMIN.ERROR
  SERVADMIN.INPUT
  TIMEOUT.IN
  ---------------------------------------------------------------------------------------------
  
  Array 2 - JVMAZURE,/www/deploy/DEV/JVMAZURE/ReceiveResponse,com.azure.RecivedResponse
  
  JVM - JVMAZURE
  Node - com.azure.RecivedResponse
  Jar - /www/deploy/DEV/JVMAZURE/ReceiveResponseDEV
  AXIOM.SVAP.IN
  EXCEPTION.QUEUE
  SERVADMIN.ERROR
  SERVADMIN.INPUT
  ---------------------------------------------------------------------------------------------
  
  Array 3 - JVMAZURE1,/www/deploy/DEV/JVMAZURE1/SendMessageToAzureCloudDEV,com.azure.SendMessageToAzureCloud
  
  JVM - JVMAZURE1
  Node - com.azure.SendMessageToAzureCloud
  Jar - /www/deploy/DEV/JVMAZURE1/SendMessageToAzureCloudDEV
  AZURE.SVAP.IN
  LOG.XML.INPUT
  AXIOM.SERVADMIN.OUTPUT
  SERVADMIN.ERROR
  SB.OUT
  TIMEOUT.IN
  ---------------------------------------------------------------------------------------------
  
  Array 4 - JVMAZURE2,/www/deploy/DEV/JVMAZURE2/SendMessageFromAzureCloudDEV,com.azure.SendMessageFromAzureCloud
  
  JVM - JVMAZURE2
  Node - com.azure.SendMessageFromAzureCloud
  Jar - /www/deploy/DEV/JVMAZURE2/SendMessageFromAzureCloudDEV
  AZURE.SVAP.IN
  SERVADMIN.ERROR
  TIMEOUT.IN
  ---------------------------------------------------------------------------------------------
  </code></pre>
  
  <p>I am trying to grep or awk for the lines/patterns below the Jar and trying to print the JVM,Node and that line I am searching for. </p>
  
  <p>So, if i am searching for <code>AXIOM.SVAP.IN</code>, I want the output to be </p>
  
  <pre><code>JVMAZURE,com.azure.ReceiveResponseFromAzure,AXIOM.SVAP.IN
  JVMAZURE,com.azure.RecivedResponse,AXIOM.SVAP.IN
  </code></pre>
  
  <p>or if i am searching for <code>SERVADMIN.ERROR</code> I want the output to be </p>
  
  <pre><code>  JVMAZURE,com.azure.ReceiveResponseFromAzure,SERVADMIN.ERROR
    JVMAZURE,com.azure.RecivedResponse,SERVADMIN.ERROR
    JVMAZURE1,com.azure.SendMessageToAzureCloud,SERVADMIN.ERROR
    JVMAZURE2,com.azure.SendMessageFromAzureCloud,SERVADMIN.ERROR
  </code></pre>
  
  <p>I have tried with awk but have not got any consistent results.</p>
  
  <p><code>cat AZURE.txt|awk -v OFS=, -v r="^'|'$" '/SERVADMIN.ERROR/ { p=$NF; gsub(r,"",p) } /EG/ { e=$NF } /Flow/ {f=$NF; gsub(r,"",f); print e,f,p }'</code></p>
  
  <p>is yiedling me </p>
  
  <pre><code>JVMAZURE,com.azure.ReceiveResponseFromAzure,
  JVMAZURE,com.azure.RecivedResponse,SERVADMIN.ERROR
  JVMAZURE1,com.azure.SendMessageToAzureCloud,SERVADMIN.ERROR
  JVMAZURE2,com.azure.SendMessageFromAzureCloud,SERVADMIN.ERROR
  </code></pre>
  
  <p>And the same result with the line/pattern changed if i search for <code>AXIOM.SVAP.IN</code></p>