Fun with File Compare

Did you know Windows has a built in file comparison tool?

There are a few things you can do to compare files and analyze differences.  If you need visual differences of merged files, version control and folder comparisons then Winmerge is a great tool for the job.  It’s fast, free and fabulous and I highly suggest it for bigger projects.  I’ve used Winmerge many times while perusing logs and it really helped me discern subtle differences.

But sometimes you don’t need all the functionality that comes with Winmerge.  That’s where FC.exe can save your butt.

Let’s get this show started.

First we need to open an Elevated Command Prompt.

fixedbyvonnie-windows-10-command-prompt

Change to the directory that contains the files you need to compare and then type:

fc filename1.txt filename2.txt

In the graphic below you can see I’m trying to compare two text files:

One is called gangnam-style.txt and the other is gangnam-style-dupe.txt.

In this case, both my files are identical so FC plainly says no differences encountered.

fixedbyvonnie-windows-10-fc-comparing-files

But this is pretty boring right?

Let’s see what happens when we introduce a change.

I replaced the first word “Hey” with “Yo” and saved the changes.

Comparing different file lines

As expected, file compare notices the difference and prints the affected line.  The file boundaries are marked off by asterisks and the output is generally easy to read.

But did you see something else here?  File compare also printed the line after the line we changed.  We don’t care about that line so we should trim the output.

You can set the number of lines to print, the line buffer, by appending the fc command with /lb (that’s a lowercase “L”) and the number of lines you want.  This is good for large files that might give you too many matches.

For example, since I only want to view a single line of matches I typed this before my filenames:

fc /lb1

Using the /lb switch with fc.exe

To include line numbers, just add the /n parameter.  Noticed I tacked that on to the previous /lb1 switch.

You can stack up options like this to create a Frankensteinian output that perfectly suits your diabolical plans.

fc.exe with line numbers using /n

Let’s see what else can do here.  In the screenshot below, I added the line “Okay maybe not” to the second file and fc.exe happily displayed the result.

Using fc.exe to compare different files

If you need to do a comparison that ignores case use the /c switch.

In the image below you can see two files with identical content.  The only difference is that one is all lowercase and the other is all uppercase.

If I try to compare these without the /c switch, fc.exe barks at me.  It thinks the files are different because the ASCII codes that represent upper and lowercase characters are different.

It’s only when I added the /c parameter that fc.exe became a cold, dispassionate, completely case insensitive command.

lol

Using fc.exe to compare while ignoring case

You can even use fc.exe to do a byte-by-byte comparison of two files.  .exe and .bin files default to byte comparison mode but if you want to force it on different file types just use the /b command option.

For example, I changed “Hey” to “Hay” in the second file and ran a byte-to-byte comparison.

You can see from the properties of each file that gangnam-style-dupe.txt is two bytes longer and that result is reflected in the command prompt output in the right.

Doing a byte-by-byte comparison with fc.exe

You can see a full list of fc parameters on Technet or by typing

 fc /?

The Bottom Line

FC can’t do everything.  It’s just a itty bitty program that does a simply ASCII or binary comparison.  But sometimes that’s all you need right?  What do you use for your text comparisons?

About

Connect with Vonnie on Twitter

Posted in Windows, Windows 10, Windows 8, Windows 8.1 Tagged with: , ,