简体   繁体   English

如何使用Powershell将csv文件转换为小写或大写,以保持其结构?

[英]How can I convert a csv file to lowercase or uppercase maintaining it's structure using powershell?

I have a CSV file that with contents that needs to be converted to all lowercase 我有一个CSV文件,其内容需要转换为所有小写字母

I have tried the code below but it doesn't maintain the CSV structure. 我已经尝试了下面的代码,但它不维护CSV结构。

(Get-Content C:\_Scratch\export.csv).ToLower() | Out-File C:\_scratch\export.csv

$Init = Import-Csv C:\_Scratch\export.csv

Is there another option I can try? 我还有其他选择可以尝试吗?

Get-Content is going to give you string array. Get-Content将为您提供字符串数组。 Add the -Raw switch to read it in as a single string, and the .toupper() and .tolower() string methods should work on that. 添加-Raw开关以单个字符串形式读取它, .toupper().tolower()字符串方法应该可以在该字符串上工作。

(Get-Content C:\_Scratch\export.csv -Raw).ToLower() | Out-File C:\_scratch\export.csv
$TempContentArray = $NULL
$TempContent = $NULL
$TempContent = Get-Content C:\_Scratch\import.csv
Foreach ($Line in $TempContent)
{
    $TempContentArray += $Line.ToUpper()
}
$TempContentArray | C:\_scratch\export.csv
$Init = Import-Csv C:\_Scratch\export.csv

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM