#How to merge csv rows based on columns into one?

4 messages · Page 1 of 1 (latest)

wild dirge
#

Example.csv
H1, H2
Column1, x
Col2, y
Column1, y

HowIwant.csv
H1, H2
Column1, "x, y"
Col2, y

fickle star
#

You can use Group-Object to consolidate rows with the same column name in the first field

#

Which version of PowerShell are you targeting?

wild dirge
#

Import-Csv 'example.csv' | Group-Object -Property H2 | Where-Object { $.count -ge 2 } | Foreach-Object { $.Group } | Select H1, H2 | Export-csv -Path output.csv -NoTypeInformation