PowerShellでは、テキストファイルを読んでいます。次に、テキストファイルに対してForeach-Objectを実行し、$arrayOfStringsNotInterestedIn
にある文字列を含まない行にのみ関心があります。
これの構文は何ですか?
Get-Content $filename | Foreach-Object {$_}
$ arrayofStringsNotInterestedInが[配列]の場合、-notcontainsを使用する必要があります。
Get-Content $FileName | foreach-object { `
if ($arrayofStringsNotInterestedIn -notcontains $_) { $) }
以上(IMO)
Get-Content $FileName | where { $arrayofStringsNotInterestedIn -notcontains $_}
-notmatch演算子を使用して、関心のある文字がない行を取得できます。
Get-Content $FileName | foreach-object {
if ($_ -notmatch $arrayofStringsNotInterestedIn) { $) }
$ arrayOfStringsNotInterestedInの文字列のいずれかを含む行を除外するには、次を使用する必要があります。
(Get-Content $FileName) -notmatch [String]::Join('|',$arrayofStringsNotInterestedIn)
Chrisが提案するコードは、$ arrayofStringsNotInterestedInに除外する完全な行が含まれている場合にのみ機能します。