Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Compare text files and show differences

Tags:

powershell

I need to do a file comparison and want to use Powershell. I need an output file listing all of the differences. The below is a good start, but I need the file to inlcude line numbers, and the resulting Input Object currently also gets cut off after 89 characters - I need the full line to display:

compare-object (get-content $File1) (get-content $File2) | Out-File $Location
like image 363
user2725402 Avatar asked Oct 16 '13 11:10

user2725402


People also ask

What PowerShell command is used to compare the difference between the content of two or more?

Compare-Object command in PowerShell is used to compare two objects. Objects can be a variable content, two files, strings, etc. This cmdlet uses few syntaxes to show the difference between objects which is called side indicators. => - Difference in destination object.

How do I compare two outputs in PowerShell?

The Compare-Object cmdlet compares two sets of objects. One set of objects is the reference, and the other set of objects is the difference. Compare-Object checks for available methods of comparing a whole object.


1 Answers

The Input Object is being truncated by the default display. To save the entire line to a file:

compare-object (get-content $File1) (get-content $File2) | format-list | Out-File $Location
like image 69
mjolinor Avatar answered Oct 24 '22 22:10

mjolinor