12-13-2023 08:59 PM
I am trying to parse a file with a complex format. It hasn't been easy as I am new to Snaplogic. In the below example, I am trying to combine the four rows. In order to do that I am thinking to assign the same seqeunce number to the group highlighted in yellow then use Aggregate to combine based on the sequence number. How do I generate the sequence number?
Solved! Go to Solution.
12-15-2023 11:15 AM
My apologies - attached here.
12-14-2023 09:48 AM
Like any other development platform, there are many solutions; here is mine for this use case. Please download and decompress the attached zip file, then import the SLP file as a new pipeline. Update the File Reader with your filename and validate to ensure it is working properly. You will need to finish adding the fields to the last Fixed Width Formatter, but I was able to see that the first few are coming out properly.
The first Fixed Width Parser is skipping the first two lines to get rid of that initial header, then using the Ignore Lines table to skip over the other headers that repeat:
Now the returned records should only contain the data we need: 4 lines per "group". So we simply use the Group By N snap with a group size of 4 to push every 4 records into one document as an array.
From here, we use a Mapper snap to concatenate the 4 records into a single string. Note the use of the Array.reduce() method in the expression:
$group.reduce((accum,cur)=> accum.concat(cur.record), '')
Basically, this just starts with an empty string, and performs the String.concat() for each "record" element in the array.
Note that I've also configured the Target Path in the Mapper as $content and set the output view of the Mapper to "Binary", which allows me to send the records into the last Fixed Width Parser snap so it can be easily split into the actual data elements that you need for the rest of your processing.
Hope this helps!
12-14-2023 10:33 AM
I will try the solutions and will get back
12-15-2023 04:34 AM
Hello Kory, I am not seeing an attachment
12-15-2023 11:00 AM
Hello @koryknick , I am not seeing an attachment
12-15-2023 11:15 AM