Hitachi

Job Management Partner 1 Version 10 Job Management Partner 1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide


diff command (compares two files)

Organization of this page

Format

diff[-a][-b][-i][-s][-w]
    [-cnum-lines|-C num-lines|-q|-unum-lines|-U num-lines|
      -y[-W output-width] [--suppress-common-lines]]
    [-L label]
     path-name-1 path-name-2
diff[-a][-b][-i][-r][-s][-w]
    [-cnum-lines|-C num-lines|-q|-unum-lines|-U num-lines|
      -y[-W output-width] [--suppress-common-lines]]
    [-L label]
     directory-name-1 directory-name-2

Description

This command compares two files.

Arguments

-a

--text

Specifies that the files are to be handled as text files.

-b

--ignore-space-change

Specifies that multiple consecutive spaces or tabs in a line are to be compressed and handled as a single space or tab. The -b and -w options cannot both be specified at the same time.

-i

--ignore-case

Specifies that differences in case are not to be considered (uppercase alphabetic letters are not to be distinguished from lowercase alphabetic letters).

-s

--report-identical-files

Specifies that a message (Files path-name-1 and path-name-2 are identical) is to be output if the contents of the files are identical.

-w

--ignore-all-space

Specifies that all spaces and tabs in a line are to be ignored. The -w and -b options cannot both be specified at the same time.

-cnum-lines

-C num-lines

--context[=num-lines]

Specifies that the path names being compared are to be output to the standard output with additions, deletions, and changes to lines indicated by the symbols +, -, and !, respectively.

The number of lines specified in num-lines are to be output for context before and after each difference. If num-lines is not specified in the -c and --context options, the default is 3 lines.

Note that when num-lines is specified in the -c option, there must not be any spaces between -c and num-lines.

-q

--brief

Specifies that if there are differences between the files, only the message Files path-name-1 and path-name-2 differ is to be output.

-unum-lines

-U num-lines

--unified[=num-lines]

Specifies that the path names being compared are to be output to the standard output with additions and deletions indicated by the symbols + and -, respectively. The old and new text are output together as a single section.

The number of lines specified in num-lines are to be output for context before and after each difference. If num-lines is not specified in the -u and --unified options, the default is 3 lines.

Note that when num-lines is specified in the -c option, there must not be any spaces between -u and num-lines.

-L label

--label=label

When the -c, -u, -C, or -U option is specified, specifies that labels are to be output in place of the path names. If one label is specified, it is output in place of path-name-1. If two labels are specified, they are output in place of path-name-1 and path-name-2, respectively, in the order they are specified.

-y

--side-by-side

Specifies that the symbols >, <, |, \, and / are to be used to indicate the difference information.

The >, <, |, \, and / symbols are output only for lines in which there is a difference in terms of line addition, deletion, or change or whether an end-of-line code is used; no symbol is output for lines in which there are no differences. The path-name-1 and path-name-2 lines are combined on one line and output side by side.

If the length of one combined line exceeds 130 columns, the lengths of the path-name-1 and path-name-2 lines are adjusted before the lines are output.

This option can be combined with the following options to change the output:

  • -W option

  • --suppress-common-lines option

-W output-width

--width=output-width

Specifies a change in the output width (number of columns) to be output per line. This option take effect when it is specified together with the -y option.

--suppress-common-lines

Specifies that lines that have no differences are not to be output. This option takes effect when it is specified together with the -y option.

path-name-1

Specifies the path name of the comparison source file.

Specify - to read the contents to be compared from the standard input. A temporary file will be created to store input from the standard input. The temporary file is output to the following directory:

  • UNIX

    Directory specified in the TMPDIR environment variable, or /var/tmp if no value has been set for TMPDIR.

  • Windows

    common-application-data-folder\HITACHI\JP1AS\misc

path-name-2

Specifies the path name of the comparison target file.

Specify - to read the contents to be compared from the standard input. A temporary file will be created to store input from the standard input. The temporary file is output to the following directory:

  • UNIX

    Directory specified in the TMPDIR environment variable, or /var/tmp if no value has been set for TMPDIR.

  • Windows

    common-application-data-folder\HITACHI\JP1AS\misc

-r

--recursive

If directories are being compared, specifies that subdirectories are to be traversed recursively.

directory-name-1

Specifies a directory as the comparison source. If you specify a file path name for either directory-name-1 or directory-name-2, the command searches for a file with the same name in the other directory. If no file with the same name is found, an error message (diff: path-name-to-compare: No such file or directory) is output.

directory-name-2

Specifies a directory as the comparison target. If you specify a file path name for either directory-name-1 or directory-name-2, the command searches for a file with the same name in the other directory. If no file with the same name is found, an error message (diff: path-name-to-compare: No such file or directory) is output.

Display formats

The diff command provides the three display formats shown below for displaying the differences between files. The output format that is used depends on the specification of options.

Format

Meaning

Traditional display format

This output format is used when none of the -c, -C, -q, -u, -U and -y options is specified.

This format displays the differences between the two files, as well as the start and end positions of the differences. In between the start and end positions, it displays the following symbols, which represent the differences:

  • a: Added

  • d: Deleted

  • c: Changed

If a difference extends across multiple lines, the numbers of the start and end lines are shown separated by the comma (,).

A difference from path-name-1 and a difference from path-name-2 are displayed in this order separated from each other by ---. < at the beginning of a line indicates a deletion or change from the first input file, while > indicates an addition or change from the second input file. One space is output after < and >.

Context format

This output format is used when the -c or -C option is specified. In addition to displaying the differences between the two files, it also displays unchanged lines before and after each difference. You can specify the number of such context lines to be displayed. The default is three lines.

Headers display the following information about the two files:

  • Boundaries between change blocks: a row of 15 asterisks (*)

  • The starting and ending positions of the differences between the two files, followed by the differences themselves

The differences are expressed as follows:

  • Line starting with +: Added line

  • Line starting with -: Deleted line

  • Line starting with !: Changed line

A single space is output after +, -, and !. Two spaces are output at the beginning of a line on which there are no differences.

Adjacent changed lines are treated as a single change block. However, when there is a gap between changed lines, another 15 asterisks are displayed and then the differences are displayed.

Unified format

This output format is used when the -u or -U option is specified. It displays the context format output as a single section. You can specify the number of lines of context to be displayed. The default is three lines.

Headers display the following information for the two files:

  • Lines that start with @@: The starting and ending positions of the differences between the two files, followed by the differences themselves

The differences are displayed as follows:

  • Line starting with +: Added line

  • Line starting with -: Deleted line

No space is output after + or -, unlike in the context format. One space is output at the beginning of an unchanged line.

Only added and deleted lines represent differences.

Adjacent changed lines are treated as a single change block. However, when there is a gap between changed lines, @@ are again used to identify lines that constitute the starting and ending positions of the differences between the two files, followed by the differences themselves.

Side-by-side format

This output format is used when the -y option is specified. The path-name-1 and path-name-2 lines are combined on one line and output side by side. By default, all lines are output regardless of whether there are any differences on lines. If the length of one combined line exceeds 130 columns, the lengths of the path-name-1 and path-name-2 lines are adjusted so that they can be displayed side by side within 130 columns.

The following symbols are displayed before the lines to indicate the difference:

  • >: Line was added

  • <: Line was deleted

  • |: Line was changed

  • \ (escape character): path-name-1 line contains no end-of-line code

  • /: path-name-2 line contains no end-of-line code

By combining the -y option with the -W and --suppress-common-lines options, you can change the output width per line and suppress output of lines that have no difference.

Traditional display format example

The following example illustrates the traditional display format.

Output example
C:\USR\JP1\oscmd\bin>diff file1 file2
1c1,2                               <--1.
< aaaaaaaaaaa                       <--2.
---                                 <--3.
> aaAAAAAaaaa                       <--4.
> bbBBBBBbbbb                       <--4.

Explanation

  1. This shows the position of a difference between file1 and file2. To represent the difference between file1 and file 2, the symbol a means added, d means deleted, and c means changed. The line number from file1 is displayed before the symbol, and the line number from file2 is displayed after it. If there are differences that span multiple lines, the start line and end line numbers are separated by the comma (,).

  2. This shows the difference line in file1.

  3. This shows the boundary between the difference lines in file1 and file2.

  4. This shows the difference lines in file2.

Context format example

Output example
C:\USR\JP1\oscmd\bin>diff -c file1 file2
*** file1       Thu May 12 20:17:54 2011  <--1.
--- file2       Thu May 12 20:18:29 2011  <--2.
***************                           <--3.
*** 1,5 ****                              <--4.
  aaaaaaaaaaa                             <--5.
! bbbbbbbb                                <--5.
  cccccccccccc                            <--5.
- dddddddddddd                            <--5.
  eeeeeeeee                               <--5.
--- 1,5 ----                              <--6.
  aaaaaaaaaaa                             <--7.
! bbbBBBbb                                <--7.
  cccccccccccc                            <--7.
  eeeeeeeee                               <--7.
+ ffffffffffffffffff                      <--7.

Explanation

  1. This shows the file name and most recent modification date and time as the information about file1.

  2. This shows the file name and most recent modification date and time as the information about file2.

  3. This shows a row of 15 asterisks (*), which represents the border between change blocks. Whenever changed lines are separated by three or more lines, this border is displayed again, and then the next change block showing differences between file1 and file2 is output.

  4. This shows the start and end positions of the file1 differences, separated by the comma (,).

  5. This shows the file1 differences. + means added, - means deleted, and ! means changed.

  6. This shows the start and end positions of the file2 differences, separated by the comma (,).

  7. This shows the file2 differences. + means added, - means deleted, and ! means changed.

Unified format example

Output example
C:\USR\JP1\oscmd\bin>diff -u file1 file2
--- file1       Thu May 12 20:17:54 2011  <--1.
+++ file2       Thu May 12 20:18:29 2011  <--2.
@@ -1,5 +1,5 @@                           <--3.
 aaaaaaaaaaa                              <--4.
-bbbbbbbb                                 <--4.
+bbbBBBbb                                 <--4.
 cccccccccccc                             <--4.
-dddddddddddd                             <--4.
 eeeeeeeee                                <--4.
+ffffffffffffffffff                       <--4.

Explanation

  1. This shows the file name and most recent modification date and time as the information about file1.

  2. This shows the file name and most recent modification date and time as the information about file2.

  3. This shows the start and end positions of the file1 changes, separated by the comma (,), a space, and then the start and end positions of the file2 changes, separated by the comma (,). The start and end positions of the file1 changes are prefixed with a -, and the start and end positions of the file2 changes are prefixed with a +.

  4. This displays as a single section the differences between file1 and file2. + indicates a line that was added in file2 from file1, and - indicates a line that was deleted in file2 from file1. Deleted lines and added lines constitute the changed portions.

Side-by-side format example

Output example
C:\USR\JP1\oscmd\bin>diff -y file1 file2
a                                     a    <--1.
b                                   | b1   <--1.
c                                     c    <--1.
d                                   <      <--1.
e                                     e    <--1.
                                    > f    <--1.
g                                   \ g    <--1.
Explanation
  1. Each line of file1 and file2 is combined into one line and then output side by side.

    > indicates a line that is not in file1 but was added in file2.

    < indicates a line that is in file1 but was deleted from file2.

    | indicates a line in file1 that has been changed in file2.

    \ indicates a line in file1 that has no end-of-line code.

    A line with no symbol has no differences.

Return codes

Return code

Meaning

0

The files are identical.

1

The files are different.

2 or greater

Error termination

Notes

Usage examples

These usage examples illustrate the results of executing the diff command on files whose contents are shown below. [Figure] represents a space and [Figure] represents a tab character.

The following examples illustrate the results of executing the command on the files shown above.