Using diff Utility217
The first part of the output is familiar. The second part shows that line 16 in the first file,
which is printed next, is not present in the second file. Sometimes it is useful to display two files
being compared in side-by-side format. This can be done by using the –
y
option. The following
command shows how to use side-by-side output. The CVS rules of displaying output are used
here to show modified, added or removed lines.
[root@boota]# diff -y --width 60 hello.c hello.c~
/*************************** /***************************
* hello.c * hello.c
* *
* This file is used to demo * This file is used to demo
* of indent utility * of indent utility
*************************** ***************************
#include #include
main () main ()
{ {
char string[30]; | char string[25];
printf ("Enter a string of printf ("Enter a string of
scanf ("%s", string); scanf ("%s", string);
printf ("The entered strin printf ("The entered strin
printf ("End of program\n" <
} }
[root@boota]#
The
--width
option is used to specify width of columns in the output. As you can see
the
|
symbol is used to show a modified line and
<
or
>
symbols are used to show added or
deleted lines.
The
diff
utility can also be used on directories. When comparing directories,
diff
com-
pares files of the same name in the two directories. Directories can also be compared recursively.
Many options are used with the
diff
command, the most common are listed in Table 7-1.
All these options start with a hyphen character.
Table7-1 Common options used with the
diff
command
OptionDescription
-b
Ignore changes in white spaces
-B
Ignore changes that are related to insertion of deletion of blank lines
-i
Ignore changes in case
-u
Unified output
-p
Used with –u option. Shows the function name also.
Next Page >>
<< Previous Page
Back to the Table of Contents