Test.ps1- $arrIn = [IO.File]::ReadAllLines('1.txt') -match '^\S+\s+\d+';
- $arrOut = [Collections.ArrayList]@();
- $dict = New-Object 'System.Collections.Generic.Dictionary[string, Int]';
-
- for ($i = 0; $i -lt $arrIn.Count; $i++) {
- $arr = $arrIn[$i] -split '\s+';
- $key = $arr[0];
- $value = 1 * $arr[1];
- $dict[$key] += $value;
- }
-
- forEach ($key In $dict.Keys) {
- [void]$arrOut.Add($key + ' ' + $dict[$key]);
- }
-
- [IO.File]::WriteAllLines('2.txt', $arrOut);
复制代码
|