Windows – COMP command – Compare files and display the differences

Windows provides COMP tool to compare the files. We will discuss about this in this Article.

Compare files and display the differences

COMP command is used to compare the content of the files and shows where the difference was identified. It compares the content byte by byte. Before it start comparing the files, first it verifies whether the files have same size. If the files are same size, it simply displays the below message and do not continue to compare the content of the files.

Files are different sizes.

If the content is same in the files, then this command displays the below message;

Files compare OK

When the content is different; it displays the differences where the content is different. For example, below command compares two files and display the differences details.

C:\>comp sample.txt notes.txt
Comparing sample.txt and notes.txt...
Compare error at OFFSET D
file1 = 65
file2 = 33
Compare error at OFFSET 12
file1 = 6F
file2 = 2D
Compare more files (Y/N) ? n

Observe that, COMP command prompts you to compare more files and once you enter “N” then it stops prompting to compare more files.

As the comparison is byte by byte, by default this command displays the offset details where the differences are identified in the files. When you are comparing the text files; it will be more easy if the command displays the line numbers instead of OFFSET values. To show the line number where the difference is; you can pass the parameter “/L”. The command looks like below;

C:\>comp firstfile.txt secondfile.txt /l

And also observe from above result that, the command displays the difference in decimal format. This format will be useful when comparing binary files. But when comparing the text files, this looks odd to see the differences in decimal format. To display the character value instead of decimal value of the character; this command provides a parameter “/A”.

For text files, if you combine the parameter “/A’ with “/L” the result will be shown in more readable form. Here it looks like;

C:\>comp sample.txt notes.txt /a /l
Comparing sample.txt and notes.txt...
Compare error at LINE 3
file1 = e
file2 = 3
Compare error at LINE 4
file1 = o
file2 = -
Compare more files (Y/N) ? n

Now you are seeing the results with line numbers where the differences in the files.

// Malin

Windows – COMP command – Compare files and display the differences

Leave a Reply

Your email address will not be published.

Scroll to top