I have a system generated log file, which includes values such as approvals and rejections transactions line by line on daily basis every 30 minutes, we require to extract and print the line of rejected transaction, currently this log file goes above 200 to 300 lines and we have to manually check the logs. Is there a way in PowerShell where I can just print the rejected values in the file eg:
logfile (actual)
[08:03:33] 1209031,,,,,status,trnasaction, requested
[08:04:33] 1548215,,,,,status,trnasaction, response
[08:06:33] 1852415,,,,,status,trnasaction, Rejected
[08:09:33] 1685941,,,,,status,trnasaction, approved
[08:11:33] 1548215,,,,,status,trnasaction, response
[08:15:33] 1852415,,,,,status,A73IF4DE5,heartbeat, Rejected
[08:21:33] 1685941,,,,,status,,transaction, Rejected
logfile (output)
[08:06:33] 1852415,,,,,status,trnasaction, Rejected
[08:15:33] 1852415,,,,,status,A73IF4DE5,heartbeat, Rejected
[08:21:33] 1685941,,,,,status,,transaction, Rejected
CodePudding user response:
You can import the log in a variable with Get-Content and then you can filter with Select-String, below a little example:
$Log = get-content "Your_Log_File"
$Log | Select-String "Rejected"