2016-07-15 46 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 
相關問題