2017-08-30 95 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