简体   繁体   English

从Azure数据湖存储文件中删除行逗号结尾

[英]Remove end of Line Comma from a Azure data lake store File

I need some inputs on file processing in Azure Data lake storage using Power Shell. 我需要使用Power Shell在Azure Data Lake存储中进行文件处理的一些输入。

I have a pipe Delimited input file in my ADLS Gen 1 Account. 我的ADLS Gen 1帐户中有一个管道定界输入文件。

The File content looks like below 文件内容如下所示

1|2|3|a,b,
3|4|5|d,h,

I am able to remove last comma using powershell in my Local PC using below code 我可以使用以下代码在本地PC中使用Powershell删除最后一个逗号

Get-Content $file_name | ForEach-Object {$_.TrimEnd(",")  } 

But when i run the same query against the same file in Azure Data lake Storage Gen 1 Account nothing happen to the data . 但是,当我对Azure Data Lake Storage Gen 1帐户中的同一文件运行相同的查询时,数据没有任何反应。 The code i am using is 我正在使用的代码是

Get-AzureRmDataLakeStoreItemContent -Account $accountName -Path $myrootdir/path/test.csv| ForEach-Object {$_.TrimEnd( ",")  }

One observation i have is that ForEach-Object is returning only once. 我有一个发现是ForEach-Object仅返回一次。 That is if i print hello inside ForEach-Object loop it prints only one. 那就是如果我在ForEach-Object循环内打个招呼,它只会打印一个。 But i verified that there is no new line problem by running -Head and -Tail command. 但是我通过运行-Head和-Tail命令验证没有换行问题。 I am attaching a screenshot for the same. 我要附上相同的屏幕截图。

Can you please help me to understand what i am doing wrong here and any alternative to remove last comma in each line. 您能否帮助我了解我在这里做错了什么,以及删除每行最后一个逗号的任何替代方法。

比较本地和ADLS之间的行为

I don't think you can modify the store item directly via powershell. 我认为您无法直接通过powershell修改商店商品。

The Get-AzureRmDataLakeStoreItemContent just gets the content. Get-AzureRmDataLakeStoreItemContent仅获取内容。 (Based on my experience, if it allows you to do that, it should be a command like Set-AzureRmDataLakeStoreItemContent or Update-AzureRmDataLakeStoreItemContent ) (根据我的经验,如果允许的话,它应该是类似Set-AzureRmDataLakeStoreItemContentUpdate-AzureRmDataLakeStoreItemContent

The workaround is to export the file -> modify it in local -> import it again. 解决方法是导出文件 ->在本地修改->再次导入

Update : 更新

If I do not misunderstand your question, try the command below. 如果我不误解您的问题,请尝试以下命令。

((Get-AzureRmDataLakeStoreItemContent -AccountName "joydatalake1" -Path "/sss/test.csv").ToString() -split("`r")).Trim() | ForEach-Object {$_.TrimEnd(",")}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Azure Data Lake Store .NET SDK创建文件 - Create File From Azure Data Lake Store .NET SDK 使用Azure Data Factory将数据从Data Lake Store(JSON文件)移动到Azure搜索 - Move data from Data Lake Store (JSON file ) to Azure Search using Azure Data Factory 如何使用来自Azure文件共享的多个线程将数据复制到Azure Data Lake存储? - How to copy data to Azure Data Lake store using multiple threads from azure file share? 使用Azure数据工厂(ADF)仅从Azure Data Lake存储中复制最新文件 - Copy only the latest file from azure data lake store with Azure Data Factory (ADF) 如何从Azure Data Lake Store中读取Azure Databricks中的JSON文件 - How to read a JSON file in Azure Databricks from Azure Data Lake Store Azure Data Lake Store基准测试 - Azure Data Lake Store Benchmarks 尝试从Data Lake存储中打开文件时抛出Microsoft.Rest.Azure.CloudException - Microsoft.Rest.Azure.CloudException was thrown when trying to open file from Data Lake store 使用 ADF 将 14gb 文件从 ftp 复制到 azure 数据湖存储 - copying 14gb file from ftp to azure data lake store using ADF 如何在Azure Data Lake存储上预处理和解压缩.gz文件? - How to preprocess and decompress .gz file on Azure Data Lake store? 使用rest api的azure数据湖存储中的更新文件出现问题 - issue with update file in azure data lake store using rest api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM