[英]Remove blank column in CSV with Azure Logic App
我在 SFTP 上有一個 CSV 文件,它有 13 列,但令人討厭的是最后一個沒有數據或 header,所以基本上每條記錄的末尾都有一個額外的逗號:
PGR,Concession ,Branch ,Branch Name ,Date ,Receipt ,Ref/EAN,Till No ,Qty , Price , Discount , Net Price ,
我想使用 Logic App 刪除最后的第 13 列並將文件重新保存在 BLOB 存儲中。 我已經從 SFTP 讀取文件並將整個文本存儲在一個變量中,然后使用 select 只獲取我需要的列,但除此之外我無法弄清楚如何將所有記錄導出到 1 clean BLOB 中的 csv 文件。
您需要處理數組中的每一行並逐一刪除最后一個逗號。 當您刪除它時,將結果添加到一個新的數組變量中。 這是流量的基礎...
這個表達式是主要的工作人員,它將刪除每行的最后一個字符......
substring(items('For_each'), 0, add(length(items('For_each')), -1))
前
后
這是邏輯應用程序的定義。 把它交給你的租戶,看看它是如何工作的。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "Result String",
"value": "@if(equals(length(items('For_each')), 0), '', concat(substring(items('For_each'), 0, add(length(items('For_each')), -1)), '\r\n'))"
},
"runAfter": {},
"type": "AppendToStringVariable"
}
},
"foreach": "@variables('CSV Data')",
"runAfter": {
"Initialize_Result_String": [
"Succeeded"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Initialize_CSV_Data": {
"inputs": {
"variables": [
{
"name": "CSV Data",
"type": "array",
"value": [
"Header1,Header2,Header3,",
"Test1.1,Test1.2,Test1.3,",
"Test2.1,Test2.2,Test2.3,",
"",
"Test3.1,Test3.2,Test3.3,",
""
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Cleansed_CSV_Data": {
"inputs": {
"variables": [
{
"name": "Cleansed CSV Data",
"type": "array"
}
]
},
"runAfter": {
"Initialize_CSV_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Result_String": {
"inputs": {
"variables": [
{
"name": "Result String",
"type": "string"
}
]
},
"runAfter": {
"Initialize_Cleansed_CSV_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Result",
"type": "string",
"value": "@variables('Result String')"
}
]
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Month",
"interval": 3
},
"recurrence": {
"frequency": "Month",
"interval": 3
},
"type": "Recurrence"
}
}
},
"parameters": {}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.