Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)

diff(1) OSS Shell and Utilities Reference Manual
Output Options
There are several choices for output format. The default output format contains lines of these
forms:
number1 a number2,number3
number1,number2 d number3
number1,number2 c number3,number4
These lines resemble ed commands to convert le1 into le2. a indicates that a line or lines were
added to one of the les; d indicates that a line or lines were deleted; and c indicates that a line
or lines were changed. The numbers after the letters pertain to le2. In fact, by exchanging a for
d and reading backward, one can ascertain how to convert le2 into le1. As in the editor ed,
identical pairs where number1 = number2 or number3 = number4 are abbreviated as a single
number.
Following each of these lines are all the lines affected in the
rst le, agged by < (left angle
bracket), then all the lines that are affected in the second le, agged by > (right angle bracket).
Except in rare circumstances, the diff command nds the smallest sufcient set of le
differences.
EXAMPLES
1. To compare two les, enter:
diff chap1.bak chap1
This command displays the differences between the les chap1.bak and chap1.
2. To compare two les, ignoring differences in the amount of white space, enter:
diff -b prog.c.bak prog.c
If two lines differ only in the number of spaces and tabs between words, then the diff
command considers them to be the same.
3. To create a le containing commands that the ed command can use to reconstruct one le
from another, enter:
diff -e ch2 ch2.old > new.old.ed
This command creates a le named new.to.old.ed that contains the ed subcommands to
change le chap2 back into the version of the text found in le chap2.old. In most
cases, new.to.old.ed is a much smaller le than chap2.old.
4. You can save disk space by deleting the le chap2.old, and you can reconstruct the le at
any time by entering:
(cat new.old.ed ; echo 1,$p) | ed - ch2 > ch2.old
The commands in parentheses add 1,$p to the end of the editing commands sent to the ed
editor. The 1,$p causes the ed command to write the le to standard output after editing
it. This modied command sequence is then piped to the ed command ( |ed), and the
editor reads it as standard input. The - ag causes the ed command to not display the le
size and other extra information, because it would be mixed with the text of le
chap2.old.
NOTES
Editing scripts that are produced by the -e or -f ags cannot create lines that consist of a single .
(dot) character.
312 Hewlett-Packard Company 527188-004