topic,counter,details1,details2
books,3,green,red
books,5,green,yellow
books,1,green,red
books,2,green,red
books,8,blue,grey
house,1,green,green
house,2,red,red
house,5,green,green
如果一行的 coloum 1,3,4 相等并且串列中有重復,那么它們應該合并。所以結果應該是這樣的。因此第 3、4、8 行被洗掉,第 1 行和第 6 行的計數器增加。
books,6,green,red
books,5,green,yellow
books,8,blue,grey
house,6,green,green
house,2,red,red
知道如何在powershell中實作嗎?
uj5u.com熱心網友回復:
使用Group-Objectcmdlet 按公共屬性值對物件進行分組,然后對counter每個組內每個物件的屬性求和:
Import-Csv ./path/to/file.csv |Group-Object topic,details1,details2 |ForEach-Object {
# for each group of distinct objects, create 1 new object where the `counter` value is the sum of all values in the group
[pscustomobject]@{
topic = $_.Group[0].topic
topic = ($_.Group |Measure-Object counter -Sum).Sum
details1 = $_.Group[0].details1
details2 = $_.Group[0].details2
}
} |Export-Csv ./path/to/output.csv -NoTypeInformation
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/374215.html
標籤:电源外壳
