2016-07-15 9 views
0

エラーログファイルには、設定されたエラー文字列と一致しないすべての行がコピーされます。だから、基本的に私は認識できないエラーのファイルを作り上げています。私はこれは私がファイルに文字列に基づいて行を削除してください

(Get-Content $path\temp_report.log) | 
    Where-Object { $_ -notmatch $error_1 } | 
    Out-File $path\uncategorised_errors.log 
(Get-Content $path\temp_report.log) | 
    Where-Object { $_ -notmatch $error_2 } | 
    Out-File $path\uncategorised_errors.log 
(Get-Content $path\temp_report.log) | 
    Where-Object { $_ -notmatch $error_3 } | 
    Out-File $path\uncategorised_errors.log 

私の入力ファイルを読むためにやっているものです

# Define all the error types that we need to search on 
$error_1 = "Start Date must be between 1995 and 9999" 
$error_2 = "SYSTEM.CONTACT_TYPE" 
$error_3 = "DuplicateExternalSystemIdException" 
$error_4 = "From date after To date in address" 
$error_5 = "Missing coded entry for provider type category record" 

と、すべての既知のエラータイプを定義

は、このようなものです:

15 Jul 2016 20:02:11,340 ExternalSystemId cannot be the same as an existing provider 
15 Jul 2016 20:02:11,340 XXXXXXXXXXXXXXXXXXXXXXXXX 
15 Jul 2016 20:02:11,340 ZZZZZZZZZZZZZZZZZZZZZZZZ 
15 Jul 2016 20:02:11,340 DuplicateExternalSystemIdException 
15 Jul 2016 20:02:11,340 DuplicateExternalSystemIdException 
15 Jul 2016 20:02:11,340 SYSTEM.CONTACT_TYPE

と私のアウトはちょうど私が3行しか持っていないと同じです:

15 Jul 2016 20:02:11,340 ExternalSystemId cannot be the same as an existing provider 
15 Jul 2016 20:02:11,340 XXXXXXXXXXXXXXXXXXXXXXXXX 
15 Jul 2016 20:02:11,340 ZZZZZZZZZZZZZZZZZZZZZZZZ

答えて

1

0はそれを試してください:

(Get-Content $path\temp_report.log) | Where-Object { $_ -notmatch $error_1 -and $_ -notmatch $error_2 -and $_ -notmatch $error_3 -and $_ -notmatch $error_4 -and $_ -notmatch $error_5} | Out-File $path\uncategorised_errors.log 
+0

作品を使用しています。私はちょうどこの作品を手に入れましたが、あなたの答えはよりエレガントで、ちょうど1つのライナーです。 $結果= Get-Content $ path \ temp_report.log $ result | Where-Object {$ _ -notmatch [regex] ::エスケープ($ error_1)} |セット内容$ path \ uncategorised_errors.log – zoomzoomvince

1

は、既知のエラーに配列を作成し、完全Select-String

[email protected](
    "Start Date must be between 1995 and 9999", 
    "SYSTEM.CONTACT_TYPE", 
    "DuplicateExternalSystemIdException", 
    "From date after To date in address", 
    "Missing coded entry for provider type category record" 
) 

Select-String -Path D:\log.txt -NotMatch -Pattern $errors 
+0

フィルター文字列中の特殊文字からの予期しない結果を避けるために、 '-SimpleMatch'を追加しました。 –

関連する問題