2016-07-15 100 views
0

我编写了下面的代码将csv转换为小写。如何使用Powershell脚本将csv转换为小写

(Get-Content "$file" -Raw).ToLower() | Out-File "$outfile" 

但得到错误,如:

Get-Content : A parameter cannot be found that matches parameter name 'Raw'. 

Here is the my error screen shot.

+1

您运行的是什么版本的PowerShell/Windows的吗? '-Raw'参数是在PowerShell 3.0 –

+0

中引入的,感谢Mathias为了您的回应,我将使用PowerShell 2.0 您的回复有帮助,我解决了我的错误,感谢好友。 [System.IO.File] :: ReadAllText($ file).ToLower()|出文件 “$ OUTFILE” –

+0

对于那些谁正在寻找第一种情况上休息下 '$文件= “C:\ TEST.CSV” $ OUTFILE = “C:\ out.csv” 获取内容$ file | ForEach-Object {$ _。substring(0,1).toupper()+ $ _。substring(1).tolower()} | Out-File $ outfile' – DisplayName

回答

1

-Raw使用PowerShell 3.0加入。如果您使用2.0或更低版本,则不存在。相反,你可以这样做:

[System.IO.File]::ReadAllText($file) 
+0

感谢您的快速回复我和我解决了我的错误。 我写简单 [System.IO.File] :: ReadAllText($ file).ToLower()| Out-File“$ outfile” 它的PowerShell版本问题......感谢Briantist。 –

3

作为替代briantist's suggestion,管从Get-Content输出到ForEach-Object并在每个单独行调用ToLower()

Get-Content $file |ForEach-Object { $_.ToLower() } |Out-File $outfile