- 论坛徽章:
- 2
|
本帖最后由 unix520 于 2023-08-07 16:05 编辑
回复 2# 本友会机友会摄友会
直接处理不行吗要转一次csv 这么繁琐吗, 但为什么执行后变多了,, 似乎并没有统加起来,,,用的ps1, 看的头晕 可以写完整的试试吗- Set-Location ${PSScriptRoot}
- #1 把不规范的txt,处理成规范的csv
- $csv = Get-Content -LiteralPath "${PSScriptRoot}20230805in.txt" | ForEach-Object {
- $_ -replace ' +',','
- } | ConvertFrom-Csv -Header 'a','b','c'
- $csv
- $根据第一列分组 = $csv | Group-Object -Property 'a'
- # group-object是一个数组,属性有:
- # 数组属性有:g[0].name ,g[0].count,g[0].group
- foreach ($i in $根据第一列分组) #遍历分组
- {
- $时间累加 = $null
- foreach ($i2 in $i.Group) #遍历分组内的第3列的每一个值
- {
- $i3 = $i2.c -replace '[a-z]' -as [timespan]
- $时间累加 += $i3
- }
- '{0} {1}' -f $i2.a,$时间累加 #输出结果
- }
- a b c
- - - -
- 老6 ID 1h:2m:59s
- 张三 ID 0h:10m:00s
- 李4 ID 0h:07m:07s
- 老6 ID 0h:01m:02s
- 老6 ID 0h:2m:59s
- 张三 ID 2h:11m:01s
- 王五 ID 0h:0m:01s
- 老6 ID 1h:2m:59s
- 张三 ID 0h:10m:00s
- 李4 ID 0h:07m:07s
- 老6 ID 0h:01m:02s
- 老6 ID 0h:2m:59s
- 张三 ID 2h:11m:01s
- 王五 ID 0h:0m:01s
复制代码
|
|