cancel
Showing results for 
Search instead for 
Did you mean: 

Parse complex file format and generate sequence number

GanguP
New Contributor III

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?

 

GanguP_0-1702529698157.png

 

1 ACCEPTED SOLUTION

koryknick
Employee
Employee

My apologies - attached here.

View solution in original post

10 REPLIES 10

koryknick
Employee
Employee

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:2023-12-14_12-36-54.png

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!

 

 

GanguP
New Contributor III

I will try the solutions and will get back

GanguP
New Contributor III

Hello Kory, I am not seeing an attachment

GanguP
New Contributor III

Hello @koryknick , I am not seeing an attachment

koryknick
Employee
Employee

My apologies - attached here.