title: Splitting CSV at each header and passing each split sequentially
body: <p>I am trying to split the below CSV File based on occurrence of &quot;Header&quot; i.e. for the payload below , two separate CSV should pass after the application of Script. Any help for this case using Groovy/JavaScript would be helpful.</p>
  <pre><code>Header|1000|SA|20210902|20210902|header text-01|USD| Line|6101200|WTAppUpload-02|2000|40005001| Line|1110100|WTAppUpload-03|2000| Line|6101200|WTAppUpload-04|1500|40005002| Line|1110100|WTAppUpload-05|1500| Line|6101200|WTAppUpload-06|1500|40005003| Line|1110100|WTAppUpload-07|1500| Header|1100|SA|20210902|20210902|header text-02|USD| Line|6101200|WTAppUpload-12|2000|40005001| Line|1110100|WTAppUpload-13||2000| Line|6101200|WTAppUpload-14|1500|40005002| Line|1110100|WTAppUpload-15|1500| Line|6101200|WTAppUpload-16|1500|40005003| Line|1110100|WTAppUpload-17|1500|
  </code></pre>
  <p>Only the last value for each Split is getting displayed by below script, we require all to be populated respectively in each split. Can someone please suggest.</p>
  <pre><code>def body= message.getBody(String.class);
  String[] value = body.split(&quot;Header&quot;);
  
  def arrayLength = value.size();
  
  message.setHeader(&quot;value&quot;,arrayLength);
  for(int i=1; i&lt;=arrayLength-1;i++) {         
  def str = value[i];
  message.setBody(str);
  }
  return message;
  </code></pre>