私はこのpsコードを持っています
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)
..
ps スクリプトを拡張して 0+1+2=3 の合計を報告する方法
私はこのpsコードを持っています
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)
..
ps スクリプトを拡張して 0+1+2=3 の合計を報告する方法
次のように正規表現で数値をキャプチャします。
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 :
参考までに、メンバーの列挙をサポートする PowerShell V3 でこれをテストしました。V2 では、これを行う必要がある場合があります。
PS> "0 warnings","1 warnings","5 warnings" | Select-String "(\d+) warnings" |
Foreach {$_.Matches | Foreach {$_.Groups[1].Value}} | Measure -Sum
これをもっと速く試すことができます:
PS II> $s="0 warnings","1 warnings","5 warnings"
PS II> [regex]::matches($s,"(\d+)\s*warnings") | measure -inp {$_.Groups[1].Value} -sum