sdiff Command
Purpose
Compares two files and displays the differences in a side-by-side format.
Syntax
Description
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.
Flags
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. |
Exit Status
Item | Description |
---|---|
1 | Successful completion. |
2 | An error occurred. |
Examples
- To print a comparison
of two files, enter:
The sdiff command displays a side-by-side listing that compares each line of the chap1.bak and chap1 files.sdiff chap1.bak chap1
- To display only the lines that differ, enter: The sdiff command displays the differences at the workstation. The -w 80 flag and variable sets the page width to 80 columns. The -s flag indicates lines that are identical in both files will not be displayed.
- To selectively combine parts of two files, enter: The sdiff command combines the chap1.bak and chap1 files into a new file called chap1.combo. For each group of differing lines, the sdiff command prompts you which group to keep or whether you want to edit them using the ed command.
- To combine and edit
two files, staff.jan and staff.apr, and write the
results to the staff.year file, perform the steps indicated.
The staff.jan file contains the following lines:
The staff.apr file contains the following lines:Members of the Accounting Department Andrea George Karen Sam Thomas
Members of the Accounting Department Andrea Fred Mark Sam Wendy
- Enter the following
command:
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:sdiff -o staff.year staff.jan staff.apr
The % (percent sign) is the command prompt.Members of the Accounting Dept Members of the Accounting Dept Andrea Andrea George | Fred %
- Enter the e b subcommand
to start editing the output file with the ed command.
The sdiff command displays a sequence of digits, indicating the byte count of lines being merged. In this case, the byte count is 23.
- Enter the q subcommand
to exit the ed command and continue combining and editing the
two files. The sdiff command displays the following:
Sam Sam Thomas | Wendy
- Enter the e b subcommand again. The ed command must be run each time a set of lines from the original two files are to be merged into the output file. The byte count in this instance is 13.
- Enter the q subcommand to save the changes. When all the lines of the two files have been merged into the output file, the q subcommand exits the ed and sdiff commands.
Members of the Accounting Department Andrea George Karen Fred Mark Sam Thomas Wendy
- Enter the following
command:
Files
Item | Description |
---|---|
/usr/bin/sdiff | Contains the sdiff command. |