[英]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. 您能否帮助我了解我在这里做错了什么,以及删除每行最后一个逗号的任何替代方法。
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-AzureRmDataLakeStoreItemContent
或Update-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.