Home > Blockchain >  Remove last blank row in CSV using Logic App
Remove last blank row in CSV using Logic App

Time:03-15

I have a CSV file stored in SFTP where the last row is a blank, so the data looks like this in text:

a,b,c
d,e,f
,,

How can I use Logic App to remove that final row and then save it in BLOB? I have the following but will need some extra steps before the BLOB creation I think.

enter image description here

CodePudding user response:

Considering the same sample here is my Logic app

enter image description here

In Compose_2 it takes the index of the last empty item. Below is the expression that I used to retrieve the lastIndex.

lastIndexOf(variables('Sample'),'\n')

Then in Compose_3 I'm selecting the one which I wanted

substring(variables('Sample'),0,outputs('Compose_2'))

Here is the Final Result

enter image description here

NOTE:- Make sure you remove an extra ' \ ' been attached to '\n' in the code view at the Compose_2.

enter image description here

So the final Compose_2 looks like

lastIndexOf(variables('Sample'),'
')

Updated Answer

If the received data is coming from CSV then you can use the take() expression you retrieve the wanted rows. Here are a few screen shots for detailed explanation:-

enter image description here

enter image description here

Below is the expression in the compose connector

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