使用 Azure 逻辑应用删除 CSV 中的空白列

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 只获取我需要的列,但除此之外我无法弄清楚如何导出所有记录到 BLOB 中的 1 个干净的 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": {}
}