0

I'm trying to split a csv file on lines. For this, I've tried alternatively with the following splitters on my flow:

<splitter expression="#[regex('^')]" doc:name="Splitter"/>

<splitter expression="#[regex('\n')]" doc:name="Splitter"/>

<splitter expression="#[regex('.*')]" doc:name="Splitter"/>

However, though the file has many lines, I'm getting the following message on the logs:

Splitter returned no results. If this is not expected, please check your split expression
Andres
  • 10,561
  • 4
  • 45
  • 63
  • Usually the `^` matches the beginning of a string, you would need to somehow set the `m` modifier (multi-line) to make `^` match the beginning of each line. Alternatively you could split on the newline character like `\n`, but something tells me it might be the case that this Mule Splitter understands that lines should be records and you REALLY should be giving the character to split the columns. I'm unfamiliar with Mule though so I could be way off with that one. – asontu Aug 25 '14 at 14:25
  • try using `.*` since it will match a complete line – Federico Piazza Aug 25 '14 at 14:41

2 Answers2

2

Finally, I found a tutorial here with the solution: http://www.dotnetfunda.com/articles/show/2070/using-mule-studio-to-read-csv-comma-seperated-value-data-from-fileinbo

The splitter has to be configured this way:

    <splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter" />

And that requires the following element to be included on the flow:

<configuration doc:name="Configuration">
    <expression-language autoResolveVariables="true">
        <import class="org.mule.util.StringUtils" />
    </expression-language>
</configuration>
Andres
  • 10,561
  • 4
  • 45
  • 63
1

This expression works for splitting CSV file :-

<splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter_For_MultipleRow"/>

And if your CSV files have a column headers like Name, Age etc .. you can use this :-

<splitter expression="#[rows=StringUtils.split(message.payload, '\n\r');ArrayUtils.subarray(rows,1,rows.size())]" doc:name="Splitter_For_MultipleRow"></splitter>
Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81