# Compare two csv-files and remove the same values

**URL:** <https://forums.powershell.org/t/compare-two-csv-files-and-remove-the-same-values/2055>\
**Category:** PowerShell Help\
**Created:** [November 11, 2013, 6:11pm UTC](https://forums.powershell.org/t/compare-two-csv-files-and-remove-the-same-values/2055 "2013-11-11T18:11:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominique-hofmann](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dominique-hofmann](https://forums.powershell.org/u/dominique-hofmann)\
**Post date:** [November 11, 2013, 6:11pm UTC](https://forums.powershell.org/t/compare-two-csv-files-and-remove-the-same-values/2055/1 "2013-11-11T18:11:43Z")

</div>

Hello Together  
I have two csv-files Path.csv and Report.csv and i want to compare the different paths, which are saved in both csv-files.  
And after it compared the csv-files i want to remove the same paths in each csv-file.  
I tried it with Select-object and where-object but it didn’t worked.  
If somebody have an idea write me thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 12, 2013, 12:15am UTC](https://forums.powershell.org/t/compare-two-csv-files-and-remove-the-same-values/2055/2 "2013-11-12T00:15:48Z")

</div>

There may be more efficient ways of doing this, but I’d use a combination of Compare-Object and the -notin or -notcontains operators, like this:

```
$csvPath1 = '.\test.csv'
$csvPath2 = '.\test2.csv'

$propertyToCompare = 'Path'

$csv1 = Import-Csv -Path $csvPath1
$csv2 = Import-Csv -Path $csvPath2

$duplicates = Compare-Object $csv1 $csv2 -Property $propertyToCompare -IncludeEqual -ExcludeDifferent -PassThru |
Select-Object -ExpandProperty $propertyToCompare

$csv1 |
Where-Object { $_.$propertyToCompare -notin $duplicates } |
Export-Csv -Path $csvPath1 -NoTypeInformation

$csv2 |
Where-Object { $_.$propertyToCompare -notin $duplicates } |
Export-Csv -Path $csvPath2 -NoTypeInformation
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:56pm UTC](https://forums.powershell.org/t/compare-two-csv-files-and-remove-the-same-values/2055/3 "2024-05-16T20:56:56Z")

</div>


