Previous section   Next section

COMPARISON COMMANDS

In a Windows environment, a user can compare two files visually by displaying each in a separate window. While graphically based file comparisons can be executed with applications that are installed on Windows 2000 or Windows Server 2003, two utilities available within the base system are executed from the command line. Two commands that compare files are fc and comp.

fc Command

The fc command enables a user to compare two files and display the differences, where both are in either an ASCII or a binary format. The syntax is

fc [options] file1 file2

The file, here shown as file1 and file2, can be just a file name, a path with a file name, or a drive, path, and file name in the format drive:path\filename. In addition, they can contain the wildcard characters * and ?. If you use a wildcard character in file1, the fc command will compare each file found to file2. In other words, it compares many to one. If you use a wildcard character in file2, the command will compare file1 to a file with a corresponding name in file2's location. Examples using the wildcard characters are given in Table A.26.

FC COMMAND EXAMPLES

To compare two binary files with the names Test.exe and Test1.exe, the command can be entered as

fc /b test.exe test1.exe

or

fc test.exe test1.exe

Table A.26. fc Command Options

Option

Description

/a

Used only for ASCII comparisons and provides the output display in abbreviated form. Only the first and last lines of each set of differences are displayed.

/b

Does a comparison of binary files. This option is automatically the default for files whose names have one of these extensions: .exe, .com, .sys, .obj, .lib, .bin. The files are compared by byte, and differences are output in the format xxxxxxxx: yy zz, where xxxxxxxx is the address of the bytes being compared in hexadecimal; yy is the contents of the byte from file1; and zz is the contents of the byte from file2.

/c

Ignores the distinctions between uppercase and lowercase.

/l

Compares ASCII files. This is considered the default for all files except those mentioned in the /b option above. The comparison is executed line by line and the differences are output in the following format: the name of file1, then the lines of file1 that differ from file2, the first line of file1 that occurs in both files, the name of file2, the lines of file2 that differ from file1, the first line of file2 that occurs in both files. After a difference is found, the command tries to resynchronize the two files.

/lbn

Sets the size of the internal line buffer to n. The default size is 100 lines. If the number of consecutive differences is greater than n, the command terminates.

/n

Displays the line numbers; used only for ASCII files.

/t

Does not treat tabs as spaces. The default is to treat tabs as spaces.

/w

Treats consecutive tabs/spaces as one space. Does not compare tabs/spaces at the beginning and end of a line.

/nnnn

Considers the file to be resynchronized when nnnn number of consecutive lines match; otherwise, matching lines are displayed as differences. The default value for nnnn is 2.

Both formats are acceptable because a file with an .exe extension is assumed to be binary by default.

To compare the files autoexec.bat, autoold.bat, and autoex3.bat to the file newauto.bat, enter the following:

fc auto*.bat newauto.bat

Suppose that a system administrator needs to compare some test result .tst files in the C:/test directory with files of the same name in test directory named bob on the D: drive. He enters

fc c:/test/*.tst d:/bob/test/*.tst

comp Command

Another comparison command available through the command line is comp, which compares the content of files by byte. Output consists of error messages of the format

Compare error at OFFSET xxxxxxxx = yy = zz

where xxxxxxxx is the memory address of the differing bytes, yy is the content of the bytes in file1, and zz is the content of the bytes in file2. The addresses and contents are in hexadecimal format unless an option is specified to display them in decimal or character format.

The syntax of the comp command is

comp [file1] [file2] [options]

The elements file1 and file2 in this line can be the names of two files, including as necessary the drive designation and the directory path. The wildcard characters * and ? can be used to compare multiple files. Options are listed in Table A.27.

Table A.27. comp Options

Option

Description

/a

Displays the differences between the files in character format.

/d

Displays the differences between the files in decimal format instead of hexadecimal.

/l

Displays the line number of the differences instead of the number of the byte offset.

/n=num

Compares the first num lines of both files, particularly when two files are different sizes.

/c

Ignores uppercase and lowercase distinctions.

EXAMPLE OF COMP COMMAND

To compare the first 15 lines of the files newtest.log and oldtest.log, displaying the line numbers where the differences occur, enter the following:

comp newtest.log oldtest.log /n=15 /l
WINDIFF

Windows Server 2003 Support Tools provides a graphical tool that compares two files, as shown in Figure A.1.

Figure A.1. Windows 2000 and Windows Server 2003 Resource Kit WinDiff

graphics/afig01.gif


  Previous section   Next section
Top