我刚刚开始使用 PowerShell,在任何地方都找不到这个问题的答案。
尝试编写一个脚本来导入 CSV 文件并搜索该文件以查看是否有任何名称相同。如果名称相同,我想将所有这些值写在同一行上,并且只显示名称一次。
例如:
Name Number
Tom 1
Tom 4
Bill 3
Dave 2
Dave 5
Dave 6
有了这个输出:
Tom- The number(s) associated with this person is/are: 1/4
Bill- The number(s) associated with this person is/are: 3
Dave- The number(s) associated with this person is/are: 2/5/6
最佳答案
像这样的管道应该可以完成这项工作
Import-Csv .\test.csv |
Group-Object Name |
Foreach-Object {
$nums = $_.Group.Number;
"{0}- The number(s) associated with this person is/are: {1}" -f $_.Name, ($nums -join '/')
}
关于csv - 对 CSV 文件中的列进行分组并连接另一列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38113586/