我編寫了下面的代碼將csv轉換爲小寫。如何使用Powershell腳本將csv轉換爲小寫
(Get-Content "$file" -Raw).ToLower() | Out-File "$outfile"
但得到錯誤,如:
Get-Content : A parameter cannot be found that matches parameter name 'Raw'.
我編寫了下面的代碼將csv轉換爲小寫。如何使用Powershell腳本將csv轉換爲小寫
(Get-Content "$file" -Raw).ToLower() | Out-File "$outfile"
但得到錯誤,如:
Get-Content : A parameter cannot be found that matches parameter name 'Raw'.
-Raw
使用PowerShell 3.0加入。如果您使用2.0或更低版本,則不存在。相反,你可以這樣做:
[System.IO.File]::ReadAllText($file)
感謝您的快速回復我和我解決了我的錯誤。 我寫簡單 [System.IO.File] :: ReadAllText($ file).ToLower()| Out-File「$ outfile」 它的PowerShell版本問題......感謝Briantist。 –
作爲替代briantist's suggestion,管從Get-Content
輸出到ForEach-Object
並在每個單獨行調用ToLower()
:
Get-Content $file |ForEach-Object { $_.ToLower() } |Out-File $outfile
您運行的是什麼版本的PowerShell/Windows的嗎? '-Raw'參數是在PowerShell 3.0 –
中引入的,感謝Mathias爲了您的迴應,我將使用PowerShell 2.0 您的回覆有幫助,我解決了我的錯誤,感謝好友。 [System.IO.File] :: ReadAllText($ file).ToLower()|出文件 「$ OUTFILE」 –
對於那些誰正在尋找第一種情況上休息下 '$文件= 「C:\ TEST.CSV」 $ OUTFILE = 「C:\ out.csv」 獲取內容$ file | ForEach-Object {$ _。substring(0,1).toupper()+ $ _。substring(1).tolower()} | Out-File $ outfile' – DisplayName