With Windows PowerShell you could do something along the lines of:
Get-Content *.log |
Where-Object { $_.StartsWith('Command:') } |
Group-Object {
$null = $_ -match '^Command: (\w+)';
$Matches[1]
} |
Select-Object Name,Count
For my test file this yields an output like
Name Count
---- -----
foo 2
bar 2
baz 1
Above code simply reads the log files line by line, pushing each line through the pipeline, it then filters the lines to only use those that start with “Command:”, indicating a command to follow. Then those lines are grouped into the individual commands. This is done by the regular expression
^Command: (\w+)
which matches the string “Command:” at the start of the line, followed by one or more word characters. This assumes the command name follows the colon and space immediately; adjust the regex accordingly if this is not the case. The command name is captured in a capture group which is used for grouping. After that only the name and frequency of the commands are selected.
The $null =
part for the match is to suppress the output of the -match
operator which would return always True
here. We don't want to group by True bar
but only by bar
.
ETA: Depending on how exactly your input looks, you might want to tweak things a bit.