En PowerShell estoy leyendo en un archivo de texto. Luego estoy haciendo un Foreach-Object sobre el archivo de texto y solo estoy interesado en las líneas que NO contienen cadenas que están en $arrayOfStringsNotInterestedIn
.
¿Cuál es la sintaxis para esto?
Get-Content $filename | Foreach-Object {$_}
Si $ arrayofStringsNotInterestedIn es una [matriz], debe usar -notcontains:
Get-Content $FileName | foreach-object { `
if ($arrayofStringsNotInterestedIn -notcontains $_) { $) }
o mejor (IMO)
Get-Content $FileName | where { $arrayofStringsNotInterestedIn -notcontains $_}
Puede usar el operador -notmatch para obtener las líneas que no tienen los caracteres que le interesan.
Get-Content $FileName | foreach-object {
if ($_ -notmatch $arrayofStringsNotInterestedIn) { $) }
Para excluir las líneas que contienen cualquiera de las cadenas en $ arrayOfStringsNotInterestedIn, debe usar:
(Get-Content $FileName) -notmatch [String]::Join('|',$arrayofStringsNotInterestedIn)
El código propuesto por Chris solo funciona si $ arrayofStringsNotInterestedIn contiene las líneas completas que desea excluir.