There may be many situations when we need to compare two files/folders in our PC. When we compare two files, we generally try to compare line by line. There are a lot of third party software available for comparing files. But today I will tell you how to compare two files line by line without installing any 3rd party software.
We can compare two files using command prompt by comp command. Lets discuss how to compare it exactly.
NOTE: In below examples I am comparing D:\Folder1\data.txt with D:\Folder2\data.txt
You need to enter your own file paths.
1. Comparing Files
(a) Case sensitive Compare For comparing two files when case is sensitive type the following.
COMP /a /l D:\Folder1\data.txt D:\Folder2\data.txt
In the above line /a is for showing the difference in ASCII format, you can replace it with /d for showing the difference in DECIMAL format and /l is for displaying the line numbers for differences.
(b) Case in-sensitive Compare For comparing two files when case is not sensitive type the following.
COMP /a /l /c D:\Folder1\data.txt D:\Folder2\data.txt
In the above line /c indicates case in-sensitivce search.
(c) Specific number of lines to compare
If you want to compare only few lines of the file then you can mention it by /n
COMP /a /l /n=13 D:\Folder1\data.txt D:\Folder2\data.txt
In the above line the number after /n indicates the number of lines to compare. In this case top 13 lines will be comapared and other lines will be skipped.
2. Comparing Folders
If you want to compare two folders then just enter path to the folders.
COMP /a /l D:\Folder1 D:\Folder2
In the above line all the notations carries the same meaning as previous. You can also use /c for case in-sensitive comparison.