I have two text files and want to find the differences between them using Windows Powershell. Is there something similar to the Unix diff tool available? Or is there another other way I haven't considered?

I've tried compare-object, but get this cryptic output:

PS C:\> compare-object one.txt two.txt

InputObject                                                 SideIndicator
-----------                                                 -------------
two.txt                                                     =>
one.txt                                                     <=
link|improve this question
feedback

6 Answers

up vote 10 down vote accepted

Figured it out myself. Because Powershell works with .net objects rather than text, you need to use get-content to expose the contents of the text files. So to perform what I was trying to do in the question, use:

compare-object (get-content one.txt) (get-content two.txt)
link|improve this answer
feedback

diff on *nix is not part of the shell, but a separate application.

Is there any reason you can't just use diff.exe under PowerShell?

You can download a version from the UnxUtils package (http://unxutils.sourceforge.net/)

link|improve this answer
feedback

You mean like Compare-Object?

link|improve this answer
See my edit to the question. – Brian Willis May 7 '09 at 3:44
feedback

WinMerge is another good GUI-based diff tool.

link|improve this answer
feedback

There's also Windiff which provides a GUI diff interface (great for use with GUI based CVS/SVN programs)

link|improve this answer
feedback

A simpler way of doing it is to write:

diff (cat file1) (cat file2)
link|improve this answer
Diff and cat are just aliases for Compare-Object and Get-Content in PowerShell. It is the same thing. – Shawn Melton Feb 10 at 1:54
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.