I am trying to taken in a sample DAT file into a Mule application.
SEC.DAT
D1030325 ADFSA 12321.00 XXXX
A1354610 AEWTF 94332.00 AAAA
V1030325 ADFSA 12321.00 XXXX
I am fairly new to the platform and having been somewhat lost on how to structure the flow in that context, but my goal is to break each record by its beginning value.
Example:
Where examples D, A, & V are the conditions.
Expected outputs:
SEC1.DAT
D1030325 ADFSA 12321.00 XXXX
SEC2.DAT
A1354610 AEWTF 94332.00 AAAA
SEC3.DAT
V1039325 AOFSA 12321.00 XXYF
This is about a Mule application to process a file. The rest of the platform has no impact for this particular question.
Assuming it is a fixed length file but not using DataWeave Fixed Length feature you can treat the input file as a single string (ie format text/xml).
First you can separate into records using a DataWeave transform to split by the end of line:
%dw 2.0
output application/java
---
payload splitBy "\n"
Following that have a <foreach>
to loop over each record. Inside the body of the <foreach>
have a <choice>
router to select to which output file write based on the first character of the record. Example of a condition: $[0] == "A"
. Then inside that branch of the <choice>
just append to a list of records or write directly to the file (with append).
Note that writing directly will not work as expected if you add any kind of concurrency because overlapping writes may corrupt the output.