Nitesh
Nitesh

Reputation: 1637

How to parse FlatFile in mulesoft

I am new to Mulesoft. I have one flatfile-

RHR001NTT PQR  2018090920180505
STR0010057830DFLT     74253J461000490
STR0020000000000000000000000000000000

I want to iterate each line and then I want to take each row to get substring from one position to another position. E.g. in row one I want substring from 6th column to 12th column.

I am trying new things to do it. I have separated each line using splitter component with #[StringUtils.split(message.payload, '\n\r')] and now I want to take substring from each line from one position to another position. I have no idea what should I do now? Is there any other way? I have heard about For-Each component.I don't have any experience or idea about For-Each and Splitter components. Please help me out. Thanks in advcance!

Upvotes: 0

Views: 494

Answers (1)

Maarten
Maarten

Reputation: 11

This configuration might help. This will iterate over each line, and the transformer splits by " ". This will give you an array. Beware the payload in the For-Each stay's in the foreach and will not exists outside it.

http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">

<flow name="xyzFlow">
    <set-payload value="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Set Payload"/>
    <foreach collection="#[payload]" doc:name="For Each">
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload splitBy " "]]></dw:set-payload>
        </dw:transform-message>
    </foreach>
</flow>

Upvotes: 0

Related Questions