powershell - Remove lines based upon string -
i have error log file want copy lines don't match set error strings. building separate file of unrecognised errors.
i define know error types
# define error types need search on $error_1 = "start date must between 1995 , 9999" $error_2 = "system.contact_type" $error_3 = "duplicateexternalsystemidexception" $error_4 = "from date after date in address" $error_5 = "missing coded entry provider type category record"
and doing read in file
(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
my input file this:
15 jul 2016 20:02:11,340 externalsystemid cannot same 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
and out same when should have 3 lines:
15 jul 2016 20:02:11,340 externalsystemid cannot same existing provider 15 jul 2016 20:02:11,340 xxxxxxxxxxxxxxxxxxxxxxxxx 15 jul 2016 20:02:11,340 zzzzzzzzzzzzzzzzzzzzzzzz
try it:
(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
Comments
Post a Comment