.TH diff "" "" Command
.PC "Compare two files"
\fBdiff [\-bdefh] [\-c \fIsymbol\^\fB] \fIfile1 file2\fR
.PP
.HS
.SH Options:
.IC \fB\-b\fR
Ignore trailing blanks; all strings of blanks are equal
.IC "\fB\-c\fI sym\fR"
Make \fBcpp\fR input conditionalized on \fIsym\fR
.IC \fB\-d\fR
Use \fB\-h\fR algorithm for large (>25,000 character) files
.IC \fB\-e\fR
Make \fBed\fR script
.IC \fB\-f\fR
Make fake (non-usable) \fBed\fR script
.IC \fB\-h\fR
Half-hearted algorithm (works on long files)
.IC \fB\-s\fR
Make \fBsed\fR script
.Pp
If either \fIfile1\fR or \fIfile2\fR is `-', stdin is used.
If one \fIfile\fR is a directory, the other \fIfile\fR
under that directory is used.
.HE
.B diff
compares
.I file1
with
.IR file2 ,
and prints a summary of the changes needed to turn
.I file1
into
.IR file2 .
.PP
Two options involve input file specification.
First, the standard input may be specified in place of a file by
entering a hyphen \*(Ql\-\*(Qr in place of
.I file1
or
.IR file2 .
Second, if
.I file1
is a directory,
.B diff
looks within that directory for a file that has the same name as
.IR file2 ,
then compares
.I file2
with the file of the same name in directory
.IR file1 .
.PP
The default output script has lines in the following format:
.DM
	1,2 c 3,4
.DE
.PP
The numbers
.I 1,2
refer to line ranges in
.IR file1 ,
and
.I 3,4
to ranges in
.IR file2 .
The range is abbreviated to a single number if the first number is
the same as the second.
The command
.IR c
was chosen from among the
.B ed
commands \*(Ql\f3a\f1\*(Qr, \*(Ql\f3c\f1\*(Qr, and \*(Ql\f3d\f1\*(Qr.
.B diff
then prints the text from each of the two files.
Text associated with
.I file1
is preceded by \*(Ql<\ \*(Qr, whereas
text associated with
.I file2
is preceded by \*(Ql>\*(Qr.
.PP
The following summarizes
.BR diff 's
options.
.IP \fB\-b\fR 0.3i
Ignore trailing blanks and treat more than one blank in an input
line as a single blank.
Spaces and tabs are considered
to be blanks for this comparison.
.IP "\fB\-c \fIsymbol\fR"
.br
Produce output suitable for the C preprocessor
.BR cpp ;
the output contains \fB#ifdef\fR, \fB#ifndef\fR, \fB#else\fR, 
and \fB#endif\fR lines.
.I symbol
is the string used to build the
.B #ifdef
statements.
If you define
.I symbol
to the C preprocessor
.BR cpp ,
it will produce
.I file2
as its output;
otherwise,
it will produce
.IR file1 .
This option does \fInot\fR work
for files that already contain \fB#ifdef\fR, \fB#ifndef\fR, \fB#else\fR,
and \fB#endif\fR statements.
.IP \fB\-e\fR
Create an
.B ed
script
that will convert
.I file1
into
.IR file2 .
.IP \fB\-f\fR
Produce a script in the same manner
as the
.B \-e
option,
but with line numbers taken directly from the two input
files.
This will work properly only if applied from end to beginning;
it cannot be used directly by
.BR ed .
.IP \fB\-h\fR
Compare large files that have a minimal number of differences.
This option uses an algorithm that is not limited
by file length, but may not discover all
differences.
.IP \fB\-d\fR
Select the
.B \-h
algorithm only for files
larger than 25,000 bytes; otherwise,
use the normal algorithm.
.SH Example
For an example of a script that uses this command, see the Lexicon entry for
.BR trap .
.SH "See Also"
.Xr "ed," ed
.Xr "egrep," egrep
.Xr "commands," commands
.Xr "zdiff" zdiff
.SH Diagnostics
.BR diff 's
exit status is zero when the files are identical,
one when they are different, and
two if a problem was encountered (e.g., could not open a file).
.SH Notes
.B diff
cannot handle files with more than 32,000 lines.
Handing
.B diff
a file that exceeds that limit will cause it to fail,
with unpredictable side effects.
