以下是我需要从
获取数据的csv文件hour, count
-----------
00,23
00,34
01,34
01,45
02,30
02,50
我想写一个power-shell脚本,我得到以下输出
hour,max(count) for unique hours
--------------------------------
00,34
01,45
02,50
我尝试使用group-object和measure-object进行分组,但是我无法获得上述期望的结果
Import-Csv d:\test\serviceyrs.csv | Measure-Object -Property count -Minimum -Maximum
给出了总的最大和最小计数,但不是我想要的
答案 0 :(得分:2)
你得到的最大值:
Import-Csv -Delimiter ',' -Path C:\sample\csv01.csv |
Group-Object -Property hour |
Select-Object -Property Name,@{N='Sum';E={($_.Group | Measure-Object -Property count -Maximum).Maximum }}
答案 1 :(得分:0)
#file which needs to be inputted
$revisedcsv="path\of\the\filename\plus_name"_revised.csv"
#filename which would have the results
$finalfilename="path\of\the\filename\plus_name+"_final.csv"
Import-Csv $revisedcsv|group hour |select @{n='MaxCount';e={($_.group|measure count -Maximum).maximum}}| export-csv $finalfilename -notype