I have a logfile with many entries. Some of them begin with a date, some others not.
I want to search for all entries from this/last month with
"UpgradeResource] part: 3-V12345678-12-"
in the line and count the results grouped by box.
Actually there are 9 boxes counting from 1 to 9 but if we buy another box there will be a 10 or 11… the box-counter is always followed by -1 at the end of the line.
The lines I search for look like this:
2016-04-27 11:49:43,895 INFO [ajp-apr-8009-exec-9] [com.xxx.shared.yyy.UpgradeResource] part: 3-V12345678-12-5-245, box: 3-V12345678-38-3-1 ... 2016-04-27 11:49:43,895 INFO [ajp-apr-8009-exec-9][com.xxx.shared.yyy.UpgradeResource] part: 3-V12345678-12-4-112, box: 3-V12345678-38-1-1
My result-output should be:
Month 03/2016: Box 1: 10 times Box 2: 123 times Box 3: 65 times Month 04/2016: Box 1: 75 times Box 2: 13 times Box 3: 147 times
I am not very firm in using powershell and tried this but get errors and think I am not on the right way:
$inputfile = "C:\temp\result.txt"
$matchstring = "(?\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*UpgradeResource] part: 3-V12345678-12-(?.*?), box: 3-V12345678-38-(\d{1})-1"
Get-Content $inputfile | foreach {
if ($_ -match $matchstring) {
"" | select @{n='Date';e={$matches.date}},@{n='Key';e={$matches.Key}},@{n='PD';e={$matches.PD}}
}
}
The Error I get:
"(?\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*UpgradeResource] part: 3-V12345678-12-(?.*?), box: 3-V1001686-38-(\d{1})-1" wird analysiert - Unbekanntes Gruppierungskonstrukt. In C:\temp\count.ps1:16 Zeichen:6 + if ($_ -match $matchstring) + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentException + FullyQualifiedErrorId : System.ArgumentException