Add CSV content to another CSV file

I have two CSV files, both have the same header:

ID,Relation,First Name,Last Name,Email Address,Office,Phone,Photos

I am trying to create a PowerShell script to copy the second csv file at the end of the first, without a header.

Is there a way to eliminate duplicate entries based on a specific column after I added them together?

+4
source share
1 answer

You Group-Objectcan use the cmdlet to group records in a specific (or several) columns. You can then iterate over the list with Foreach-Objectand simply select the first entry in each group, which will give you a great list. Finally, you can export the CSV using the cmdlet Export-Csv:

Import-Csv "your-csv.path"  | 
    Group -Property 'Id' | 
    ForEach-Object { $_.Group | select -first 1} |
    Export-Csv -Path 'your_csv.path'
+4

Source: https://habr.com/ru/post/1674276/


All Articles