我尝试使用谷歌搜索不同的东西,但我似乎无法找到答案。
"ColumnOne","ColumnTwo","ColumnThree"
"C1V1","C2V1","C3V1"
"C1V2","C2V2","C3V2"
"C1V2","C2V2","C3V2"
"C1V3","C2V3","C3V3"
$input = 'C:\Temp\test.csv'
$inputCsv = Import-Csv $input | Select-Object -Unique
$inputCsv | Export-Csv "$input-temp.csv" -NoTypeInformation
#Move-Item "$input-temp.csv" $input -Force
"ColumnOne","ColumnTwo","ColumnThree"
"C1V2","C2V2","C3V2"
"ColumnOne","ColumnTwo","ColumnThree"
"C1V1","C2V1","C3V1"
"C1V2","C2V2","C3V2"
"C1V3","C2V3","C3V3"
有办法做到这一点吗?
答案 0 :(得分:3)
您需要使用Select-Object或Sort-Object指定列名称以获得唯一结果。如果您想要排序,请尝试以下代码。如果您不想,请使用Select-Object。
$input = 'C:\Temp\test.csv'
$inputCsv = Import-Csv $input | Sort-Object * -Unique
$inputCsv | Export-Csv "$input-temp.csv" -NoTypeInformation
您还可以参考博客HERE。