我建议使用switch
语句来快速处理输入文件(按 PowerShell 标准):
# Get an array of all the column values of interest.
$allColValues = switch -File E:\Test\test.txt {
default { # each input line
# For better performance with *literal* separators,
# use the .Split() *method*.
# Generally, however, use of the *regex*-based -split *operator* is preferable.
$_.Split([char] 0x1c)[117] # hex 0x1c is octal 034
}
}
# Group the column values, and only output those that occur at least
# twice.
$allColValues | Group-Object -NoElement | Where-Object Count -ge 2 |
Select-Object Name, Count | Export-Csv E:\Test\test2.csv -NoTypeInformation
向Mathias R. Jessen 致敬,感谢他提出了转换的建议,该转换通过仅维护抽象组信息-NoElement
来简化呼叫;也就是说,只有分组标准(反映在 中,而不是组成组的各个对象(通常反映在 中)通过输出对象返回。Group-Object
.Name
.Group
至于你尝试了什么: