Home > Blockchain >  Skip first x rows in CSV using Azure Logic App
Skip first x rows in CSV using Azure Logic App

Time:03-15

I have a CSV file in SFTP where the data looks like this:

rubbish1,rubbish2,rubbish3
blank1,blank2,blank3
header1,header2,header3
data1,data2,data3
data4,data5,data6

I want to be able skip the first 3 rows and then resave the file in BLOB storage using Azure Logic App. Ideally if I can make it dynamic by simply feeding a "SkipFirstNumberOfRows" parameter so I can replicate this for other files then that'd be great, but I'd like to get it working first at least for this file. Later on I'd also like to be able to pass a "SkipLastNumberOfRows" but that's much futher down the line...

CodePudding user response:

Considering the same sample that you have provided, Im using 3 compose Connectors in order to skip the first Rows. Here is my Logic app

enter image description here

I'm using Split To Get Rows Connector in order to convert the csv file into Arrays. Below is the expression in it

split(body('Get_blob_content_(V2)'),'

')

The above steps creates an extra empty array object In order to remove it Im using the next step Rows Array connector. Below is the expression in it

take(outputs('Split_To_Get_Rows'),sub(length(outputs('Split_To_Get_Rows')),1))

Going further In Skip First Number of Rows Connector is used to skip the first 3 rows. Here is the expression in it

take(skip(outputs('Rows_Array'),3),sub(length(outputs('Rows_Array')),1))

Here is the Final Result:

enter image description here

  • Related