Compares two files and displays the differences in a side-by-side format.
The sdiff command reads the files specified by the File1 and File2 parameters, uses the diff command to compare them, and writes the results to standard output in a side-by-side format. The sdiff command displays each line of the two files with a series of spaces between them if the lines are identical. It displays a < (less than sign) in the field of spaces if the line only exists in the file specified by the File1 parameter, a > (greater than sign) if the line only exists in the file specified by the File2 parameter, and a | (vertical bar) for lines that are different.
When you specify the -o flag, the sdiff command merges the files specified by the File1 and File2 parameters and produces a third file.
Note: The sdiff command invokes the diff -b command to compare two input files. The -b flag causes the diff command to ignore trailing spaces and tab characters and to consider other strings of spaces as equal.
Item | Description |
---|---|
-l | Displays only the left side when lines are identical. |
-o OutFile | Creates a third file, specified by the OutFile variable,
by a controlled line-by-line merging of the two files specified by
the File1 and the File2 parameters. The following subcommands
govern the creation of this file:
|
-s | Does not display identical lines. |
-w Number | Sets the width of the output line. The default value of the Number variable is 130 characters. The maximum width of the Number variable is 2048. The minimum width of the Number variable is 20. The sdiff command uses 2048 if a value greater than 2048 is specified. |
sdiff chap1.bak chap1
The sdiff command
displays a side-by-side listing that compares each line of the chap1.bak and chap1 files. The staff.jan file contains the following lines:
Members of the Accounting Department
Andrea
George
Karen
Sam
Thomas
The staff.apr file contains the following
lines: Members of the Accounting Department
Andrea
Fred
Mark
Sam
Wendy
sdiff -o staff.year staff.jan staff.apr
The sdiff command
will begin to compare the contents of the staff.jan and staff.apr files
and write the results to the staff.year file. The sdiff command
displays the following: Members of the Accounting Dept Members of the Accounting Dept
Andrea Andrea
George | Fred
%
The % (percent sign) is the command prompt. The sdiff command displays a sequence of digits, indicating the byte count of lines being merged. In this case, the byte count is 23.
Sam Sam
Thomas | Wendy
Members of the Accounting Department
Andrea
George
Karen
Fred
Mark
Sam
Thomas
Wendy
Item | Description |
---|---|
/usr/bin/sdiff | Contains the sdiff command. |