# Compare two csv-files and output the diff

**URL:** <https://forums.powershell.org/t/compare-two-csv-files-and-output-the-diff/476>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/compare-two-csv-files-and-output-the-diff/476 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/compare-two-csv-files-and-output-the-diff/476/1 "2011-12-31T18:30:00Z")

</div>

by PatricF at 2013-01-10 00:02:12

> Hi,  
>   
> I have two .csv-files, master.csv and slave.csv, and I need to compare those two and get the difference to output in a file.  
>   
> The master.csv-file contains the up-to-date entries and slave.csv contains the entries that are "active" and need to be updated.  
> In master.csv there might have been entries added or removed and I need the diff in two files, lets say master.added.csv and master.removed.csv and in those files there are Only the entries that got added/removed and nothing more.  
>   
> Is this possible?  
>   
> Let me explain this in a little more simpler way.  
>   
>   
> master.csv contains:  
>   
> `Firstname;Lastname;EmailJohn;Doe;John@example.comSteve;Andersson;steve@company.comJames;Smith;james@aol.com`  
>   
> slave.csv:  
> `Firstname;Lastname;EmailJohn;Doe;John@example.comDavid;Williams;david@hotmail.com`  
>   
> To in this case I should get these files:  
>   
> master.added.csv:  
> `Firstname;Lastname;EmailSteve;Andersson;steve@company.comJames;Smith;james@aol.com`  
>   
> master.removed.csv:  
> `Firstname;Lastname;EmailDavid;Williams;david@hotmail.com`  
>   
> I hope you understand what I’m looking for. Is this possible?  
>   
> Thanks,  
> -Patric

by nohandle at 2013-01-10 01:09:51

> Yes, you can do it, and if the data are in the same format in both files you can do it quite easily I suppose.   
> I would try to handle the files as plain text. Loading them in memory and comparing them.   
> see these posts:   
> [viewtopic.php?f=2&t=923](https://powershell.org/discuss/viewtopic.php?f=2&t=923)  
> [viewtopic.php?f=2&t=991](https://powershell.org/discuss/viewtopic.php?f=2&t=991)  
>   
> If you have any problems implementing this, let me know.

by PatricF at 2013-01-10 01:10:57

> Thanks for the quick reply, I will check this out!

by PatricF at 2013-01-10 05:11:25

> It worked perfectly, thank you very much!

---

<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, 9:03pm UTC](https://forums.powershell.org/t/compare-two-csv-files-and-output-the-diff/476/2 "2024-05-16T21:03:34Z")

</div>

Closed on May 16, 2024, 9:03pm UTC


