What is the Windows equivalent of the diff command?

WindowsCmdDiff

Windows Problem Overview


I know that there is a post similar to this : here.
I tried using the comp command like it mentioned, but if I have two files, one with data like "abcd" and the other with data "abcde", it just says the files are of different sizes. I wanted to know where exactly they differ. In Unix, the simple diff tells me which row and column, the comp command in windows works if I have something like "abd" and "abc". Not otherwise. Any ideas what I can use for this?

Windows Solutions


Solution 1 - Windows

Run this in the CMD shell or batch file:

FC file1 file2

FC can also be used to compare binary files:

FC /B file1 file2

Solution 2 - Windows

Well, on Windows I happily run diff and many other of the GNU tools. You can do it with cygwin, but I personally prefer GnuWin32 because it is a much lighter installation experience.

So, my answer is that the Windows equivalent of diff, is none other than diff itself!

Solution 3 - Windows

Winmerge has a http://manual.winmerge.org/Command_line.html">command line utility that might be worth checking out.

Also, you can use the graphical part of it too depending on what you need.

Solution 4 - Windows

Another alternative is to download and install git from here. Then, add the path to Git\bin\ to your PATH variable. This will give you not only diff, but also many other linux commands that you can use from the windows command line.

You can set the PATH variable by right clicking on Computer and selecting Properties. Then you can click on Advanced System Settings on the left side of the screen. In the pop up, click Environment Variables and then either add or update the PATH variable in your user variables with Git\bin\

Git diff documentation

Solution 5 - Windows

FC works great by in my case it was not helpful as I wanted just the lines that are changed. And FC give additional data like file name, same lines and bilateral comparison.

    >fc data.txt data.txt.bak   
    ***** DATA.TXT
    ####09
    ####09
    ####09
    ***** DATA.TXT.BAK
    ####09
    ####08
    ####09

but in my case I wanted only the lines that have changed and wanted those lines to be exported to different file, without any other header or data.

So I used "findstr" to compare the file :

findstr /V /G:data.txt.bak data.txt >DiffResult.txt

where :

data.txt.bak is the name of old file

data.txt is the name of new file

DiffResult.txt contains the data that is changed i.e just one line ####09

Solution 6 - Windows

There's also Powershell (which is part of Windows). It ain't quick but it's flexible, here's the basic command. People have written various cmdlets and scripts for it if you need better formatting.

PS C:\Users\Troll> Compare-Object (gc $file1) (gc $file2)

Not part of Windows, but if you are a developer with Visual Studio, it comes with WinDiff (graphical)

But my personal favorite is BeyondCompare, which costs $30.

Solution 7 - Windows

fc. fc is better at handling large files (> 4 GBytes) than Cygwin's diff.

Solution 8 - Windows

DiffUtils is probably your best bet. It's the Windows equivalent of diff.

To my knowledge there are no built-in equivalents.

Solution 9 - Windows

The reason you getting the error with COMP is that the utility assumes the files that you are comparing are of the same size. To overcome that you can use th '/n' option with which you can specify the number of lines you want to compare. (see the options supported by comp by typing 'comp /?' on the command line. so your command would look like :

C:\>comp "filepath1" "filepath2" /a /l /n=(the number of lines you want to compare) /c 

This should solve your problem if you wanna stick to using COMP. But this will be a problem for really large files.

Though comp is an option, but I feel it is primitive and FC is a better option. you can use FORFILES and FC together to probably make a really good filecompare utility if you require one on a frequent basis.

FC is used this way for ref:

C:\>fc /c(case insensistive) /lbn(number of errors allowed before you wanna stop compare) /n(display line number) "filename1" "filename2"

there are many options available which you can see by 'fc /?' hope this helps

Solution 10 - Windows

I've found a lightweight graphical software for windows that seems to be useful in lack of diff command. It could solve all of my problems.

WinDiff http://www.grigsoft.com/download-windiff.htm

Solution 11 - Windows

The windows equivalent to the diff command is the fc (File Comapre) command.

Here are the basic steps to do so:

  1. Keep the two files in a folder (Example file1.html and file2.html)
  2. Launch command prompt
  3. Type fc file1Location file2Location

Have found a detailed tutorial on the same:

http://www.howtogeek.com/206123/how-to-use-fc-file-compare-from-the-windows-command-prompt/

Solution 12 - Windows

I don't know if the following tool is exatly what you need. But I like to use, for specific files, some online tool. This way I can use it regardless of the operational system. Here is a example: diffchecker.com

But for my needs, I guess the best tool to track changes and logs of my project's files is GIT. If you work in a team, you can have some repo online in a server of yours, or use it with Bitbucket or Github.

Hope it helps somebody.

Solution 13 - Windows

If you have installed git on your machine, you can open a git terminal and just use the Linux diff command as normal.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwittythothaView Question on Stackoverflow
Solution 1 - WindowsAndriy MView Answer on Stackoverflow
Solution 2 - WindowsDavid HeffernanView Answer on Stackoverflow
Solution 3 - WindowsRobert GreinerView Answer on Stackoverflow
Solution 4 - WindowsTim HutchisonView Answer on Stackoverflow
Solution 5 - WindowsNimish ChoudharyView Answer on Stackoverflow
Solution 6 - WindowsPaul WilliamsView Answer on Stackoverflow
Solution 7 - Windowsnerdfever.comView Answer on Stackoverflow
Solution 8 - WindowsmattkellyView Answer on Stackoverflow
Solution 9 - WindowsproximaceView Answer on Stackoverflow
Solution 10 - WindowsAhmadView Answer on Stackoverflow
Solution 11 - WindowsVishal KotakView Answer on Stackoverflow
Solution 12 - WindowsPedro AcácioView Answer on Stackoverflow
Solution 13 - WindowsfalsePocketsView Answer on Stackoverflow