Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
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 file1 into file2. a indicates that a line or lines were
added to one of the files; 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 file2. In fact, by exchanging a for
d and reading backward, one can ascertain how to convert file2 into file1. 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
first file, flagged by < (left angle
bracket), then all the lines that are affected in the second file, flagged by > (right angle bracket).
Except in rare circumstances, the diff command finds the smallest sufficient set of file
differences.
EXAMPLES
1. To compare two files, enter:
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 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 file containing commands that the ed command can use to reconstruct one file
from another, enter:
diff -e ch2 ch2.old > new.old.ed
This command creates a file named new.to.old.ed that contains the ed subcommands to
change file chap2 back into the version of the text found in file chap2.old. In most
cases, new.to.old.ed is a much smaller file than chap2.old.
4. You can save disk space by deleting the file chap2.old, and you can reconstruct the file 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 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 to not display the file
size and other extra information, because it would be mixed with the text of file
chap2.old.
NOTES
Editing scripts that are produced by the -e or -f flags cannot create lines that consist of a single .
(dot) character.
3−12 Hewlett-Packard Company 527188-007