A Solaris Admin trying to work with log files in a Windows world. I am trying to tail a Log File, but there are 6 repeating lines that I'd like to ignore. I've been able to select the lines with:
Get-Content alert.log -Tail 300 -Wait | Select-String -Pattern "WARNING: too" -Context 1,6
But I'm trying to ignore these 'Context' lines. I have tried adding -NotMatch
to the end, but it ends up printing the lines I'm trying to ignore.
In Solaris I would do:
tail -300f alert.log | egrep -B1 -A6 -v "WARNING: too"
I'm trying to find a PowerShell equivalent, without success. I have had success with ignoring the one matching line:
Get-Content alert.log -Tail 300 | ?{$_ -notmatch 'WARNING: too'}
But how do I extend this to the line above and 6 below? The types of lines I want to ignore are:
2020-05-20T15:32:13.870875+10:00
WARNING: too many parse errors
PARSE ERROR:
2020-05-20T15:32:13.886503+10:00
begin ORACLE PL/SQL; end;
Additional information: hd=00007FF6E4A08E68
...Current username=FRED
...Application: work3wp.exe
Action: I've been able create this statement:
Get-Content .\alert_prod.log -Tail 300 -Wait | ?{$_ -notmatch "WARNING: too|begin FRED|Additional information|Current username|Application: work3wp.exe|PARSE ERROR:" }
But the date/time stamp at the start of the error appears each time. I want the date/time stamp of other errors.