Per DeDor
Per DeDor

Reputation: 51

Powershell compare two files and generate third file

I have 2 files - file1.txt and file2.txt. I want to compare these two files with powershell and generate third file (file3.txt) which containst all the lines from file1.txt minus lines in file2.txt

Here is an example of how the files 1 and 2 looks like:

file1.txt content

Line1
Line2
Line3
Line4

file2.txt content

Line2
Line4

And I want file3.txt to look like this

Line1
Line3

Can you think of some way how to do this?

Upvotes: 2

Views: 3390

Answers (1)

TheMadTechnician
TheMadTechnician

Reputation: 36287

This one is ridiculously easy...

Compare-Object (Get-Content File1.txt) -DifferenceObject (Get-Content File2.txt) -PassThru | Out-File File3.txt

That's all there is to it.

Upvotes: 8

Related Questions