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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -