Powershell: Display last X lines of a log that match a criteria and keep watching the file -
i trying watch log file occurrences of word ("purge"). want display last 10 matching lines (at time command runs) , keep watching file newly appended lines match criteria.
so far, got something working powershell:
get-content .\callaudit.engine.log -tail 10 -wait | {$_ -match "purge"}
this works, gets last (any) 10 lines , applies filter.
i want
- get matching last 10 lines
- have command keep watching file.
can done?
-tail 10
won't because purge
-filter executed after has read last 10 lines (which may or may not contain purge
).
i split 2 calls. 1 list last 10 values, , 1 monitor.
get-content -path .\callaudit.engine.log | where-object {$_ -match "purge"} | select-object -last 10 get-content -path .\callaudit.engine.log -wait -tail 0 | where-object {$_ -match "purge"}
Comments
Post a Comment