title: How to transpose data after when match found in array
body: <p>I want data to be in csv format from xml data</p>
  <p><strong>xml data to test is available in this question</strong>
  <a href="https://stackoverflow.com/questions/67245123/extract-data-between-tags-t-t/67245640?noredirect=1#comment118870633_67245640">extract data between tags &lt;t&gt; &lt;/t&gt;</a></p>
  <p><strong>Note :</strong> The data in xml file might differ and Headers will differ as well</p>
  <p>In this xml their are 3 headers -&gt; <code>NAME,AGE,COURSE</code></p>
  <p><strong>I have Used below command to get data in horizontal format ,all in one line :</strong></p>
  <pre><code>awk -F'(&lt;/*t&gt;|&lt;/*t&gt;)' 'NF&gt;1{for(i=2;i&lt;NF; i=i+2) printf(&quot;%s%s&quot;, $i, (i+1==NF)?ORS:OFS)}' OFS=',' demo.xml
  </code></pre>
  <p><strong>After running above command , below is the output</strong>
  &quot;NAME&quot;,&quot;Vikas&quot;,&quot;Vijay&quot;,&quot;Vilas&quot;,&quot;AGE&quot;,&quot;24&quot;,&quot;34&quot;,&quot;35&quot;,&quot;COURSE&quot;,&quot;MCA&quot;,&quot;MMS&quot;,&quot;MBA&quot;</p>
  <p><strong>How i am trying to implement logic</strong></p>
  <p>Take parameter from user , how many header values will be their</p>
  <p>In above xml their are 3 headers -&gt; <code>NAME,AGE,COURSE</code></p>
  <p><code>header_count=3</code></p>
  <p>So 3 headers means will have 3 values like : <code>HEADER + 3</code> values
  NAME,Vikas,Prabhas,Arjun -&gt; this will be transpose to below</p>
  <p><strong>Output :</strong></p>
  <pre><code>NAME,
  Vikas,
  Prabhas,
  Arjun,
  </code></pre>
  <p>Same goes with header value <strong>AGE</strong> -&gt; <code>AGE + 3</code> values</p>
  <pre><code>AGE,25,34,21  will be transpose to vertical 
  
  AGE
  25
  34
  21
  </code></pre>
  <p>Same goes with header value <strong>COURSE</strong> -&gt; <code>COURSE + 3</code> values</p>
  <pre><code>COURSE,MCA,MBA,MMS  will be transpose to vertical 
  
  COURSE
  MCA
  MBA
  MMS
  </code></pre>
  <p>**Expected Output after combing all data for NAME,AGE,COURSE **</p>
  <pre><code>NAME,AGE,Course
  Vikas,&quot;25&quot;,MCA
  Prabhash,&quot;34&quot;,MBA
  Arjun,&quot;21&quot;,MMS
  </code></pre>