Merge two csvs

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of GoogleUser20 GoogleUser20 1 year, 9 months ago.

  • Author
    Posts
  • #22572
    Profile photo of GoogleUser20
    GoogleUser20
    Participant

    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.

  • #22573
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.)

  • #22636
    Profile photo of GoogleUser20
    GoogleUser20
    Participant

    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

You must be logged in to reply to this topic.