Help to match one csv column with a column in another csv file

I have a csv file called csvpaths.csv with one column called Path that contains a url path. I have another .csv file called analyticsdata.csv that has a column called Path. I want to read a record from the csvpaths.csv and compare it against the analysticdata.csv column called Path. If there is a match I want to write the row of data from the analyticsdata.cvs out to a csv file called matches.csv. If no match then loop to the next row of data in the csvpaths.csv file.
Appreciate any help… I’m a Powershell beginner.

Welcome to the forum. :wave:t4:

What kind of help do you need?

Please keep in mind: This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

What have you tried so far? We expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further. :wink:

1 Like

I have 2 CSV files. CSV file 1 contains a column called ‘Page’ that has a list of webpages URLs. I have a second CSV file 2 that contains the same column called Page along with columns ‘Page Title’ and Pageviews… This file contains all the analytics data. I have this script that does a Compare-Object. The intent is find a match with a record in CSV file1 to a record in CSV file 2 and write out to CSV file 3 the row from CSV File2. Right now the script writes out all the rows from CSV file 2.

$CSV1 = Import-CSV -Path .\GoogleAnalytics\AnalyticsData.csv
[array]$Header = Get-Content .\GoogleAnalytics\WebCadURLS.csv | Select-Object -first 1

$Fields = $CSV1[0].psobject.Properties.Name

$CSV2 = Import-CSV .\GoogleAnalytics\WebCadURLS.csv | Select $Fields

$Deltas = Compare-Object -ReferenceObject ($CSV1 | ConvertTo-Csv) -DifferenceObject ($CSV2 | ConvertTo-Csv) | Select-Object -ExpandProperty InputObject
$Header += $Deltas

$Header | Out-File ".\GoogleAnalytics\CSVDeltas.csv"

I think you are overcomplicating this. Try the following and inspect the result:

$CSV1 = Import-CSV -Path .\GoogleAnalytics\AnalyticsData.csv
$CSV2 = Import-CSV -Path .\GoogleAnalytics\WebCadURLS.csv 

$Deltas = Compare-Object -ReferenceObject $CSV1 -DifferenceObject $CSV2 -Property Page -PassThru