Reputation: 51
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
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