Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ diff(1) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

comm

bdiff

cmp

ed, red

sdiff



DIFF(1,C)                   AIX Commands Reference                    DIFF(1,C)



-------------------------------------------------------------------------------
diff



PURPOSE

Compares text files.

SYNTAX


        +--------+   +---------------+
diff ---|        |---| +-----------+ |--- file1 --- file2 ---|
        | +----+ |   +-| -b        |-+
        +-| -e |-+    ^| -c        ||
          | -f |      || -D string ||
          | -h |      || -l        ||
          | -n |      || -r        ||
          +----+      || -s        ||
                      || -S name   ||
                      || -i        ||
                      || -t        ||
                      || -w        ||
                      |+-----------+|
                      +-------------+


DESCRIPTION

The diff command compares file1 and file2 and writes to standard output
information about what changes must be made to make them identical.  If you
specify a - (minus) for file1 or file2, the diff command reads standard input.
If file1 is a directory, the diff command uses a file in that directory with
the name file2.  If file2 is a directory, the diff command uses a file in that
directory with the name file1.  If both file1 and file2 are directories, the
contents of the directories are sorted and the diff command processes all text
files that differ in the directories.  Binary files that differ, common
subdirectories, and files that appear in only one directory are listed.

The typical output contains lines in these forms:

+------------------+-------+------------------+
|Lines Affected in |       |  Lines Affected  |
|file1             | Action| in file2         |
+------------------+-------+------------------+
|num1              | a     | num2[,num3]      |
+------------------+-------+------------------+
|num1[,num2]       | d     | num3             |
+------------------+-------+------------------+
|num1[,num2]       | c     | num3[,num4]      |
+------------------+-------+------------------+



Processed November 8, 1990         DIFF(1,C)                                  1





DIFF(1,C)                   AIX Commands Reference                    DIFF(1,C)




These lines resemble ed subcommands to convert file1 into file2.  The numbers
before the action letters pertain to file1; those after pertain to file2.
Thus, by exchanging a for d and reading backward, you can also tell how to
convert file2 into file1.  As in ed, identical pairs (where num1 = num2) are
abbreviated as a single number.

Following each of these lines, the diff command displays all lines affected in
the first file preceded by a <, then all lines affected in the second file
preceded by a >.

Except in rare circumstances, the diff command finds a smallest sufficient set
of file differences.  An exit value of 0 indicates no differences, 1 indicates
differences found, and 2 indicates an error.

Note:  Editing scripts produced by the -e or -f flags cannot create lines
       consisting of a single period (.).

FLAGS

-b Ignores trailing spaces and tab characters and considers other strings of
   blanks to compare as equal.

-c Produces a diff with lines of context.  The default is to present three
   lines of context.  You can change the default by specifying a number after
   the c.  With this option, the output format is modified slightly.  The
   output begins with identification of the files involved and their creation
   dates, and then each change is separated by a line with 12 asterisks.  The
   lines removed from file1 are marked with "-", and those added to file2 are
   marked with "+".  Lines that are changed from one file to the other are
   marked in both files with "!".

-D string
   Causes the diff command to create a merged version of file1 and file2 on the
   standard output, with C preprocessor controls included so that a compilation
   of the result without defining string is equivalent to compiling file1,
   while defining string will yield file2.

-e Produces output in a form suitable for use with the ed command to convert
   file1 to file2.

-f Produces output in a form not suitable for use with ed, showing the
   modifications necessary to convert file1 to file2 in the reverse order of
   that produced under the -e flag.

-h Performs a faster comparison.  This flag only works when the changed
   sections are short and well separated, but it does work on files of any
   length.  The -c, -Dstring, -e, and -f flags are not available when you use
   the -h flag.

-i Ignore case.




Processed November 8, 1990         DIFF(1,C)                                  2





DIFF(1,C)                   AIX Commands Reference                    DIFF(1,C)



-l If both files specified are directories, this flag produces a long output
   format.  Each text file the diff command prints is piped through pr(1) to
   paginate it, and other differences are summarized after all text file
   differences are reported.

-n Produces output in a form not suitable for use with the ed command, showing
   the modifications necessary to convert file1 to file2.

-r If both files specified are directories, this option causes the diff command
   to be applied recursively through all common subdirectories involved.

-s If both files specified are directories, this option causes the diff command
   to report files which are the same.  Normally, these files are not
   mentioned.

-S name
   If both files specified are directories, this option starts the directory
   comparison after encountering the file name.

-t Expands tabs on output.

-w Ignores blanks.

EXAMPLES

  1. To compare two files:

      diff chap1.bak chap1

    This command displays the differences between the files "chap1.bak" and
    "chap1".

  2. To compare two files, ignoring differences in the number of blanks:

      diff  -b  prog.c.bak  prog.c

    If two lines differ only in the number of blanks and tabs between words,
    the diff command considers them to be the same.

  3. To create a file containing commands that the ed command can use to
    reconstruct one file from another:

      diff  -e  chap2  chap2.old  >new.to.old.ed

    This command creates a file named "new.to.old.ed" that contains the ed
    commands used to change "chap2" back into the version of the text found in
    "chap2.old".  In most cases, the file "new.to.old.ed" is a much smaller
    than the file "chap2.old".  You can save disk space by deleting the file
    "chap2.old", but you can reconstruct the file at any time by entering:

      (cat new.to.old.ed ; echo  '1,$p') | ed  -  chap2  >chap2.old




Processed November 8, 1990         DIFF(1,C)                                  3





DIFF(1,C)                   AIX Commands Reference                    DIFF(1,C)



    The commands in parentheses add "1,$p" to the end of the list of editing
    commands sent to the ed command.  The "1,$p" causes the ed command to write
    the file to standard output after editing it.  This modified command
    sequence is then piped to the ed command ("| ed"), and the editor reads it
    as standard input.  The "-" flag causes the ed command not to display the
    file size and other extra information since these would be mixed with the
    text of the file "chap2.old".  (See page sh-20 for details about
    grouping commands with parentheses).

FILES

/tmp/d?????    Temporary files.
/usr/lib/diffh For the -h flag.

RELATED INFORMATION

See the following commands:  "bdiff" "cmp,"  "comm," "ed, red," and  "sdiff."






































Processed November 8, 1990         DIFF(1,C)                                  4



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026