Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ diff(1) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

comm

bdiff

cmp

ed

sdiff

diff

PURPOSE

     Compares text files.

SYNOPSIS
     diff [ -efbh ] file1 file2


DESCRIPTION

     The diff command  compares file1 and file2  and writes to
     standard output  information about  what changes  must be
     made to  bring them into  agreement.  If you specify  a -
     (minus) for  file1 or  file2, diff reads  standard input.
     If file1  is a directory, then  diff uses a file  in that
     directory with the name file2.   If file2 is a directory,
     then diff  uses a  file in that  directory with  the name
     file1.

     The normal output contains lines of these forms:

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

     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, diff 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,  diff finds a smallest suf-
     ficient  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 con-
        siders other strings of blanks to compare as equal.
     -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 sepa-
        rated, but it  does work on files of  any length.  The
        -e and -f flags are not  available when you use the -h
        flag.

EXAMPLES

     1.  To compare two files:

           diff chap1.bak chap1

         This  displays  the  differences  between  the  files
         "chap1.bak" and "chap1".
     2.  To  compare two  files, ignoring  differences in  the
         amount of white space:

           diff  -b  prog.c.bak  prog.c

         If two lines differ only  in the number of blanks and
         tabs between  words, then  diff considers them  to be
         the same.
     3.  To create a file containing  commands that ed can use
         to reconstruct one file from another:

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

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

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

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

FILES

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

RELATED INFORMATION

     The  following commands:   "bdiff" "cmp,"  "comm,"  "ed,"
     and  "sdiff."

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