Trim 使用 PowerShell 的多个项目 CSV

Trim multiple items CSV using PowerShell

我需要修改一些基本代码以支持根据不同的字符串过滤结果字段中的多个项目。例如,我需要过滤掉所有不遵循 "Version is 2.x.x.x.x" 或“found”或任何其他组合模式的内容。

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

明白了.....我确信我的正则表达式有一个更简洁的版本,但它确实有效。

$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