If you want a count per log file report here are a couple of ways of doing it in v1.0 and v2.0 CTP
$word = 'Error'
# v1.0
Get-ChildItem *.log |
Where-Object {Select-String "\b$word\b" $_.fullname -quiet} |
Select-Object FullName, @{name = 'Count';
expression = {@((Get-Content $_.fullname |
Out-String).split() -match "\b$word\b").count}} |
Format-Table -auto
# faster
Get-ChildItem *.log |
Where-Object {Select-String "\b$word\b" $_.fullname -quiet} |
Select-Object FullName, @{name = 'Count';
expression = {@([regex]::matches((Get-Content $_.fullname),
"\b$word\b", 1)).count}} |
Format-Table -auto
# one-liner versions
ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={@((gc $_.fullname|out-string).split()-match"\b$word\b").count}}|ft -a
# faster
ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={@([regex]::matches((gc $_.fullname),"\b$word\b",1)).count}}|ft -a
### v2.0 CTP ###
Get-ChildItem *.log |
Where-Object {Select-String "\b$word\b" $_.fullname -quiet} |
Select-Object FullName, @{name = 'Count';
expression = {@((gc $_.fullname |
Out-String) -split ' ' -match "\b$word\b").count}} |
Format-Table -auto
# fastest
Get-ChildItem *.log |
Where-Object {Select-String "\b$word\b" $_.fullname -quiet} |
Select-Object FullName, @{name = 'Count';
expression = {Select-String "\b$word\b" $_.fullname -all |
ForEach-Object {$total = 0} {$total += $_.matches.count} {$total}}} |
Format-Table -auto
# one-liner versions
ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={@((gc $_.fullname|Out-String)-split' '-match"\b$word\b").count}}|ft -a
# fastest
ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={Select-String "\b$word\b" $_.fullname -all|%{$total=0}{$total+=$_.matches.count}{$total}}}|ft -a
--
Kiron