2017-08-30 98 views
-4

我需要修改一些基本代碼以支持基於不同字符串篩選結果字段中的多個項目。例如,我需要過濾掉所有不符合「版本爲2.x.x.x.x」或「找到」或任意數量的其他組合的模式。使用PowerShell修改多個項目CSV

$FileIn = '.\FileIn.Csv' 
$FileOut = '.\FileOut.Csv' 
$Keywords = '\sVersion is*', '\sFound\s' 
Foreach($keyword in $keywords){ 
(Get-Content $FileIn) -replace $keyword,'' | Set-Content $FileOut } 
+2

對不起但:你的問題是什麼? – Richard

+2

你的問題是不準確的。你想要過濾掉什麼?只需使用'Import-Csv myinputfile.csv | Where-Object {$ _。Results -notmatch'regexpattern'}'。 –

+2

你有試過什麼嗎?堆棧溢出不是代碼寫入服務。如果你有嘗試過的東西,它失敗了,或者研究過它或者任何嘗試......那麼這是你的地方。如果你想要某人爲你編寫代碼,那麼你應該聘請一名開發人員。 – ArcSet

回答

0

明白了.....我敢肯定有我的正則表達式的清潔版本,但它的工作原理。

$Keywords = '\sVersion\sis\s.{2,16}', '\sfound', '\sshould.{2,40}','\sfile' 
$Csv | ForEach-Object { 
ForEach($keyword in $Keywords){ 
$_.Results = $_.Results -replace $keyword,'' 
}} 
$Csv | Export-Csv $FileOut -NoTypeInformation