title: Mule 4.4 DataWeave append counter to file
body: <p>I am reading in a file (see below). The example file has 13 rows.</p>
  <pre><code>A|doe|chemistry|100|A|
  B|shea|maths|90|A|
  C|baba|physics|80|B|
  D|doe|chemistry|100|A|
  E|shea|maths|90|A|
  F|baba|physics|80|B|
  G|doe|chemistry|100|A|
  H|shea|maths|90|A|
  I|baba|physics|80|B|
  J|doe|chemistry|100|A|
  K|shea|maths|90|A|
  L|baba|physics|80|B|
  M|doe|chemistry|100|A|
  </code></pre>
  <p>Then iterating over these rows using a for each ( batch size 5 ) and then calling a REST API
  Depending on REST API response ( success or failure ) I am writing payloads to respective success / error files.</p>
  <p>I have mocked the called API such that first batch of 5 records will fail and rest of the files will succeed.</p>
  <p>While writing to success / error files am using the following transformation :</p>
  <pre><code>output application/csv quoteValues=true,header=false,separator=&quot;|&quot;
  ---
  payload
  </code></pre>
  <p>All of this works fine.<br />
  Success log file:</p>
  <pre><code>&quot;F&quot;|&quot;baba&quot;|&quot;physics&quot;|&quot;80&quot;|&quot;B&quot;
  &quot;G&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  &quot;H&quot;|&quot;shea&quot;|&quot;maths&quot;|&quot;90&quot;|&quot;A&quot;
  &quot;I&quot;|&quot;baba&quot;|&quot;physics&quot;|&quot;80&quot;|&quot;B&quot;
  &quot;J&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  &quot;K&quot;|&quot;shea&quot;|&quot;maths&quot;|&quot;90&quot;|&quot;A&quot;
  &quot;L&quot;|&quot;baba&quot;|&quot;physics&quot;|&quot;80&quot;|&quot;B&quot;
  &quot;M&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  </code></pre>
  <p>Error log file:</p>
  <pre><code>&quot;A&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  &quot;B&quot;|&quot;shea&quot;|&quot;maths&quot;|&quot;90&quot;|&quot;A&quot;
  &quot;C&quot;|&quot;baba&quot;|&quot;physics&quot;|&quot;80&quot;|&quot;B&quot;
  &quot;D&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  &quot;E&quot;|&quot;shea&quot;|&quot;maths&quot;|&quot;90&quot;|&quot;A&quot;
  </code></pre>
  <p>Now what I want to do is append the row/line number to each of these files so when this goes to production , whoever is monitoring these files can easily understand and correlate with the original file .
  So as an example in case of error log file ( the first batch failed which is rows 1 to 5 ) I want to append these numbers to each of the rows:</p>
  <pre><code>&quot;1&quot;|&quot;A&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  &quot;2&quot;|&quot;B&quot;|&quot;shea&quot;|&quot;maths&quot;|&quot;90&quot;|&quot;A&quot;
  &quot;3&quot;|&quot;C&quot;|&quot;baba&quot;|&quot;physics&quot;|&quot;80&quot;|&quot;B&quot;
  &quot;4&quot;|&quot;D&quot;|&quot;doe&quot;|&quot;chemistry&quot;|&quot;100&quot;|&quot;A&quot;
  &quot;5&quot;|&quot;E&quot;|&quot;shea&quot;|&quot;maths&quot;|&quot;90&quot;|&quot;A&quot;
  </code></pre>
  <p>Not sure what I should write in DataWeave to achieve this?</p>