I have this ps code
PS > Select-String -path .\build-count-warn.txt -pattern "[1-9]?[0-9]+ warn"
warn.txt:1: 0 Warning(s)
warn.txt:2: 1 Warning(s)
warn.txt:3: 2 Warning(s)
..
So how to extend the ps script and report the sum of 0+1+2=3
Capture the numeric value in the regex like so:
PS> "0 warnings","1 warnings","5 warnings" | Select-String "(\d+) warnings" |
Foreach {$_.Matches.Groups[1].Value} | Measure -Sum
Count : 3
Average :
Sum : 6
Maximum :
Minimum :
Property :
FYI I tested this on PowerShell V3 which supports member enumeration. On V2, you may need to do this:
PS> "0 warnings","1 warnings","5 warnings" | Select-String "(\d+) warnings" |
Foreach {$_.Matches | Foreach {$_.Groups[1].Value}} | Measure -Sum