我一直试图从 csv 文件获取有意义的输出。
原始输入看起来像这样。
Col1,Col2,Col3,Col4
a,2,b,z
a,2,c,x
a,1,d,y
e,1,f,s
e,2,g,t
h,1,k,r
我正在尝试实现以下输出(不包括 col4)并导出到文件以使用 PowerShell 2 进行进一步报告。
a 5 b,c,d
e 3 f,g
h 1 k
我的脚本函数的代码是:
$data = import-csv $filename.csv | Select-Object -property Col1,Col2,Col3
$view | Group Col1 | `
select Name,@{
Name="Col2Sum";
Expression = {
[math]::round(($_.Group | Measure-Object -Sum Col2).Sum/60,2)
}
} | `
Sort "Col2Sum" -desc | ft -auto -GroupBy Col | out-file $file.txt
我陷入困境的是如何在一行中从 Col3 生成数组并正确输出它们。
如果有人有任何想法。