[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 5

sdiff Command

Purpose

Compares two files and displays the differences in a side-by-side format.

Syntax

sdiff-l | -s ] [  -o OutFile ] [  -w Number ] File1 File2

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

-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:
e
Starts the ed command with an empty file.
e b or e |
Starts the ed command with both sides.
e l or e <
Starts the ed command with the left side.
e r or e >
Starts the ed command with the right side.
l
Adds the left side to the output file.
r
Adds the right side to the output file.
s
Stops displaying identical lines.
v
Begins displaying identical lines.
q
Performs one of the following functions:
  • Exits the ed command.
  • Exits the sdiff command if no ed command is running.
  • Exits both commands. This action occurs when there are no more lines to be merged into the output file.

Each time you exit from the ed command, the sdiff command writes the resulting edited file to the end of the file specified by the OutFile variable. If you do not save the changes before exiting (for example, you press the Ctrl-C key sequence), the sdiff command writes the initial input to the output 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.

Examples

  1. To print a comparison of two files, enter:

    sdiff chap1.bak chap1 

    The sdiff command displays a side-by-side listing that compares each line of the chap1.bak and chap1 files.

  2. To display only the lines that differ, enter:
    sdiff  -s  -w 80 chap1.bak chap1
    The sdiff command displays the differences at the work station. 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.
  3. To selectively combine parts of two files, enter:
    sdiff  -s  -w 80  -o chap1.combo chap1.bak chap1
    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.
  4. 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:

    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
    1. Enter the following command:

      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.

    2. 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.

    3. 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
        
    4. 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.
    5. 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.
    The staff.year file now contains the following:

    Members of the Accounting Department
    Andrea
    George
    Karen
    Fred
    Mark
    Sam
    Thomas
    Wendy

Files

/usr/bin/sdiff Contains the sdiff command.

Related Information

The diff command, ed command.

Files Overview, Input and Output Redirection Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]