2013-10-28 118 views
0

我有一個文本文件,我想從該文件中刪除特殊字符。例如: - 在文本中輸入文件從文本文件中刪除特殊字符

++Mathematics 
--Chemistry 
(Physics) 
$#History) 
%%Geography 

現在我想在文本文件來替換所有的特殊字符的字符串的和想要的輸出爲: - 數學 化學 物理 歷史 地理

我已經在我的powershell腳本中使用了替換命令,但儘管替換了特殊字符,它仍然刪除了我的文本文件中的所有值。

get-content D:\Share\SCCM-Powershell_Commands\edit.txt 
Foreach-object {$_ -replace "\&", "" -replace "\£", "" -replace "\+", "" -replace "\-", "" -replace "\)","" -replace "\(","" -replace "\$","" -replace "\#","" -replace "\*",""}| 
Set-Content D:\Share\SCCM-Powershell_Commands\edit1.txt 

get-content D:\Share\SCCM-Powershell_Commands\edit.txt 

同時有人也可以建議如何開始學習PowerShell。我是PowerShell的新手,想學習Powershell腳本。

回答

0

嘗試這樣:

foreach ($line in (Get-Content D:\Share\SCCM-Powershell_Commands\edit.txt)) { 
    $line -replace "\&", "" -replace "\£", "" -replace "\+", "" -replace "\-", "" -replace "\)","" -replace "\(","" -replace "\$","" -replace "\#","" -replace "\*","" -replace "\%","" 
} | Set-Content D:\Share\SCCM-Powershell_Commands\edit1.txt 

Get-Content D:\Share\SCCM-Powershell_Commands\edit1.txt 
相關問題