Author Posts

February 12, 2015 at 5:55 pm

I have two CSV files which share one column called database in common. I am looking to merge both CSVs into one. Here is a summary of what I am looking for.

file1.csv

Database Size freespace
DB1 100 50
DB2 80 55
DB3 90 40

File2.csv

Database MBXCount WhiteSpace
DB1 20 50
DB2 100 2
DB3 50 9

Desired file
MergedFile.csv

Database Size freespace MBXCount WhiteSpace
DB1 100 50 20 50
DB2 80 55 100 2
DB3 90 40 50 9

Any help would be appreciated.

February 12, 2015 at 6:09 pm

The PowerShell team made a blog post on this a couple years ago: [url="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx"]Join-Object[/url]. As long as your set size is not too huge, it works great. (It doesn't scale well; very slow when you're trying to merge thousands of records.)

February 13, 2015 at 6:26 pm

Thanks for the feedback. I actually went with merge-csv function. It did what I was looking for.

http://www.powershelladmin.com/wiki/An_Advanced_Cmdlet_to_Merge_Csv_Files_in_PowerShell