### Unified Format Example Output Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Example output generated by the 'diff -u lao tzu' command. ```text --- lao 2002-02-21 23:30:39.942229878 -0800 +++ tzu 2002-02-21 23:30:50.442260588 -0800 @@ -1,7 +1,6 @@ -The Way that can be told of is not the eternal Way; -The name that can be named is not the eternal name. The Nameless is the origin of Heaven and Earth; -The Named is the mother of all things. +The named is the mother of all things. + Therefore let there always be non-being, so we may see their subtlety, And let there always be being, @@ -9,3 +8,6 @@ The two are the same, But after they are produced, they have different names. +They both may be called deep and profound. +Deeper and more profound, +The door of all subtleties! ``` -------------------------------- ### diff3 --show-all (-A) Three-Way Conflict Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Marking-Conflicts.html This example demonstrates the output of a three-way conflict when using the --show-all (-A) option with diff3. ```text <<<<<<< lao ||||||| tzu They both may be called deep and profound. Deeper and more profound, The door of all subtleties! ======= -- The Way of Lao-Tzu, tr. Wing-tsit Chan >>>>>>> tao ``` -------------------------------- ### diff3 --show-all (-A) Example Output Source: https://www.gnu.org/software/diffutils/manual/html_node/Marking-Conflicts.html The --show-all (-A) option brackets conflicts and outputs all changes from older to yours, not just unmerged ones. This example shows a conflict where only 'tzu' differs. ```text <<<<<<< tzu ======= The Way that can be told of is not the eternal Way; The name that can be named is not the eternal name. >>>>>>> tao ``` -------------------------------- ### Example of file content for --ignore-blank-lines Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt A snippet of file content used to illustrate the effect of the --ignore-blank-lines (-B) option. ```text 1. A point is that which has no part. ``` -------------------------------- ### Example 'ed' Script Output Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt This is an example of the output generated by 'diff -e lao tzu'. It shows commands for the 'ed' editor to transform one file into another. ```diff 11a They both may be called deep and profound. Deeper and more profound, The door of all subtleties! . 4c The named is the mother of all things. . 1,2d ``` -------------------------------- ### Start Comparison from a Specific File Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Use '--starting-file=FILE' or '-S FILE' to begin comparing only the specified file and all alphabetically later files in the top directory. ```bash diff -S specific_file.txt directory1 directory2 ``` -------------------------------- ### Example diff3 output for three files Source: https://www.gnu.org/software/diffutils/manual/html_node/diff3-Hunks.html Displays the output format of diff3 when comparing three files F, G, and H. ```text ====2 1:1c 3:1c a 2:1c g ==== 1:3c f 2:3c g 3:3c h ``` -------------------------------- ### Example of recommended patch header Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt A corrected patch header format ensuring consistent directory structure for better compatibility. ```diff diff -Naur v2.0.29/prog/README v2.0.30/prog/README --- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800 +++ v2.0.30/prog/README 2002-03-17 20:49:32.442260588 -0800 ``` -------------------------------- ### Display Help Message Source: https://www.gnu.org/software/diffutils/manual/html_node/diff3-Options.html The --help option outputs a summary of usage information for diff3 and then exits. This is a standard option for getting quick help on command-line tools. ```bash diff3 --help ``` -------------------------------- ### Context Format Header Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Context.html This is the two-line header that precedes the hunks in the context output format. It indicates the files being compared and their modification times. ```diff *** from-file from-file-modification-time --- to-file to-file-modification time ``` -------------------------------- ### Ignore all space comparison example Source: https://www.gnu.org/software/diffutils/manual/html_node/White-Space.html Demonstrates how the --ignore-all-space (-w) option treats lines as equivalent even when white space is missing or added, including carriage returns. ```text Here lyeth muche rychnesse in lytell space.-- John Heywood$ He relyeth much erychnes seinly tells pace. --John Heywood ^M$ ``` -------------------------------- ### Example of Conditional Formatting for Line Count Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt An example demonstrating conditional formatting for the number of lines (N) in a group. It outputs 'no lines' if N is 0, '1 line' if N is 1, and '%dN lines' otherwise. ```bash %(N=0?no:%dN) line%(N=1?:s) ``` -------------------------------- ### Unified Format Hunk Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html Hunks represent areas where files differ. They start with '@@' followed by line number information for both files. Lines common to both files start with a space, added lines with '+', and removed lines with '-'. ```diff @@ from-file-line-numbers to-file-line-numbers @@ line-from-either-file line-from-either-file... ``` -------------------------------- ### Ignore space change comparison example Source: https://www.gnu.org/software/diffutils/manual/html_node/White-Space.html Demonstrates how the --ignore-space-change (-b) option treats lines with varying white space sequences as equivalent. ```text Here lyeth muche rychnesse in lytell space. -- John Heywood$ Here lyeth muche rychnesse in lytell space. -- John Heywood $ ``` -------------------------------- ### Diff Output Example 2 Source: https://www.gnu.org/software/diffutils/manual/html_node/Hunks.html This output shows hunks when 'a' is changed to 'c' and 'c' is changed to 'a', highlighting a different hunk grouping strategy. ```text 1c1 < a --- > c 3c3 < c --- > a ``` -------------------------------- ### Select Changes for Merging Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Examples of using diff3 options to select specific types of changes for merging. ```text Output of 'diff3 -e lao tzu tao': 11a -- The Way of Lao-Tzu, tr. Wing-tsit Chan . 8c so we may see their result. . Output of 'diff3 -3 lao tzu tao': 8c so we may see their result. . Output of 'diff3 -x lao tzu tao': 11a -- The Way of Lao-Tzu, tr. Wing-tsit Chan . ``` -------------------------------- ### Example of ambiguous patch header Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt An example of a patch header with inconsistent slash counts, which can cause issues for patch consumers. ```diff diff -Naur v2.0.29/prog/README prog/README --- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800 +++ prog/README 2002-03-17 20:49:32.442260588 -0800 ``` -------------------------------- ### Display Custom Labels in Diff Output Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Example output showing the use of the --label option to replace file names in the header. ```text *** original --- modified ``` -------------------------------- ### Unified Format Header Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html The unified output format begins with a two-line header indicating the files being compared and their modification times. The timestamp format may vary based on host system capabilities. ```diff --- from-file from-file-modification-time +++ to-file to-file-modification-time ``` -------------------------------- ### Generate RCS script output Source: https://www.gnu.org/software/diffutils/manual/html_node/RCS.html Example output generated by running diff -n on two files. ```text d1 2 d4 1 a4 2 The named is the mother of all things. a11 3 They both may be called deep and profound. Deeper and more profound, The door of all subtleties! ``` -------------------------------- ### Verbose Merge TeX Files with Custom Formats Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt An equivalent to the previous example, but explicitly defines formats for unchanged and changed groups as well. This provides a more detailed control over the diff output. ```shell diff \ --old-group-format='\begin{em} %<\end{em} ' \ --new-group-format='\begin{bf} %>\end{bf} ' \ --unchanged-group-format='%=' --changed-group-format='\begin{em} %<\end{em} \begin{bf} %>\end{bf} ' \ old new ``` -------------------------------- ### Diff Output Example 1 Source: https://www.gnu.org/software/diffutils/manual/html_node/Hunks.html This output shows hunks when 'a' and 'b' are deleted and 'b' and 'a' are added. It demonstrates a specific way `diff` might group differences. ```text 1,2d0 < a < b 3a2,3 > b > a ``` -------------------------------- ### Context Format Hunk Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Context.html A single hunk in the context output format, showing lines of context and differing lines marked with indicators. Use this to understand file differences. ```diff *************** *** from-file-line-numbers **** from-file-line from-file-line... --- to-file-line-numbers ---- to-file-line to-file-line... ``` -------------------------------- ### Display Version Information Source: https://www.gnu.org/software/diffutils/manual/html_node/diff3-Options.html The -v or --version option outputs the version information for GNU diff3 and then exits. This is useful for checking the installed version of the utility. ```bash diff3 -v ``` -------------------------------- ### Example `ed` Script Output Source: https://www.gnu.org/software/diffutils/manual/html_node/Example-ed.html This is the output of the `diff -e` command, showing changes to be applied to one file to make it match another. It uses `ed` command syntax. ```diff 11a They both may be called deep and profound. Deeper and more profound, The door of all subtleties! . 4c The named is the mother of all things. . 1,2d ``` -------------------------------- ### diff3 --show-overlap (-E) and -X Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Marking-Conflicts.html The --show-overlap (-E) and -X options bracket the first and third files for three-way overlapping changes, outputting only unmerged changes and excluding the second file's content. ```text <<<<<<< lao ======= -- The Way of Lao-Tzu, tr. Wing-tsit Chan >>>>>>> tao ``` -------------------------------- ### Correct Diff Header Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Avoiding-Common-Mistakes.html Generate patch headers with consistent file names, ensuring both old and new file paths have the same number of slashes for predictable behavior across different `patch` utility versions. ```diff diff -Naur v2.0.29/prog/README v2.0.30/prog/README --- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800 +++ v2.0.30/prog/README 2002-03-17 20:49:32.442260588 -0800 ``` -------------------------------- ### diff3 Normal Format Output Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Example-diff3-Normal.html This output shows differences between three files using diff3's normal format. It indicates changed, added, and deleted lines across the files. ```diff ====2 1:1,2c 3:1,2c The Way that can be told of is not the eternal Way; The name that can be named is not the eternal name. 2:0a ====1 1:4c The Named is the mother of all things. 2:2,3c 3:4,5c The named is the mother of all things. ====3 1:8c 2:7c so we may see their outcome. 3:9c so we may see their result. ==== 1:11a 2:11,13c They both may be called deep and profound. Deeper and more profound, The door of all subtleties! 3:13,14c -- The Way of Lao-Tzu, tr. Wing-tsit Chan ``` -------------------------------- ### Side-by-Side Diff Output Example Source: https://www.gnu.org/software/diffutils/manual/html_node/Example-Side-by-Side.html This output shows the result of comparing two files using 'diff -y -W 72'. The '<' indicates lines only in the first file, '>' indicates lines only in the second file, and '|' indicates lines that differ between the two files. Lines without a symbol are common to both files. ```text The Way that can be told of is n < The name that can be named is no < The Nameless is the origin of He The Nameless is the origin of He The Named is the mother of all t | The named is the mother of all t > Therefore let there always be no Therefore let there always be no so we may see their subtlety, so we may see their subtlety, And let there always be being, And let there always be being, so we may see their outcome. so we may see their outcome. The two are the same, The two are the same, But after they are produced, But after they are produced, they have different names. they have different names. > They both may be called deep and > Deeper and more profound, > The door of all subtleties! ``` -------------------------------- ### Configure --ifdef equivalent options Source: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-If_002dthen_002delse.html This sequence of options defines the output format for old, new, unchanged, and changed line groups using shell syntax. ```shell --old-group-format='#ifndef name %<#endif /* ! name */ ' \ --new-group-format='#ifdef name %>#endif /* name */ ' \ --unchanged-group-format='%=' \ --changed-group-format='#ifndef name %<#else /* name */ %>#endif /* name */ ' ``` -------------------------------- ### Formatting Unchanged Lines Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Formats lines that are common to both files. The example uses '%l' to represent the line content without its trailing newline. ```bash --unchanged-line-format=' %l ' ``` -------------------------------- ### Merge C source code with ifdef directives Source: https://www.gnu.org/software/diffutils/manual/html_node/If_002dthen_002delse.html Example output generated by diff --ifdef=HAVE_WAITPID showing conditional compilation blocks. ```c do { #ifndef HAVE_WAITPID if ((w = wait (&s)) < 0 && errno != EINTR) #else /* HAVE_WAITPID */ if ((w = waitpid (-1, &s, 0)) < 0 && errno != EINTR) #endif /* HAVE_WAITPID */ return w; } while (w != child); ``` -------------------------------- ### Equivalent options for --ifdef=NAME Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Shows the sequence of group format options that implement the --ifdef functionality. ```bash --old-group-format='#ifndef NAME %<#endif /* ! NAME */ ' \ --new-group-format='#ifdef NAME %>#endif /* NAME */ ' \ --unchanged-group-format='%=' \ --changed-group-format='#ifndef NAME %<#else /* NAME */ %>#endif /* NAME */ ' ``` -------------------------------- ### Diff Output Format - Normal Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Example of 'diff -n F G' output, which shows differences in a normal format without a trailing newline. ```text d1 1 a1 1 g ``` -------------------------------- ### Inserting a Character by Octal Code Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Inserts a character specified by its octal code O (1 to 3 digits). For example, '\0' represents the null character. ```bash %c'\O' ``` -------------------------------- ### Diff Output Format - Ed Script Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Example of 'diff -e F G' output, which reports errors and provides an ed script for applying changes. ```text 1c g . ``` -------------------------------- ### Show All Unmerged Changes Source: https://www.gnu.org/software/diffutils/manual/html_node/diff3-Options.html The -A or --show-all option incorporates all unmerged changes from the second file into the first, surrounding conflicts with bracket lines. This provides a comprehensive view of all differences. ```bash diff3 -A file1 file2 file3 ``` -------------------------------- ### List POSIX-compliant patch options Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Standard options for instructions intended for broad compatibility across GNU, traditional, and POSIX patch implementations. ```text -c -d DIR -D DEFINE -e -l -n -N -o OUTFILE -pNUM -R -r REJECTFILE ``` -------------------------------- ### Formatting New Lines with Line Numbers Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Formats lines exclusively from the second file. The example uses '%l' to represent the line content without its trailing newline. ```bash --new-line-format='|%l ' ``` -------------------------------- ### sdiff Command Line Options Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt A list of supported command line arguments for the sdiff utility. ```APIDOC ## sdiff Command Line Options ### Description Options for configuring the behavior of the sdiff file comparison and merging utility. ### Parameters #### Options - **--diff-program=PROGRAM** (string) - Optional - Use the compatible comparison program PROGRAM to compare files instead of diff. - **-E, --ignore-tab-expansion** (flag) - Optional - Ignore changes due to tab expansion. - **--help** (flag) - Optional - Output a summary of usage and then exit. - **-i, --ignore-case** (flag) - Optional - Ignore changes in case. - **-I REGEXP, --ignore-matching-lines=REGEXP** (string) - Optional - Ignore changes that just insert or delete lines that match REGEXP. - **-l, --left-column** (flag) - Optional - Print only the left column of two common lines. - **-o FILE, --output=FILE** (string) - Required - Put merged output into FILE. - **-s, --suppress-common-lines** (flag) - Optional - Do not print common lines. - **--speed-large-files** (flag) - Optional - Use heuristics to speed handling of large files. - **--strip-trailing-cr** (flag) - Optional - Strip any trailing carriage return at the end of an input line. - **-t, --expand-tabs** (flag) - Optional - Expand tabs to spaces in the output. - **--tabsize=COLUMNS** (integer) - Optional - Assume that tab stops are set every COLUMNS (default 8). - **-v, --version** (flag) - Optional - Output version information and then exit. - **-w COLUMNS, --width=COLUMNS** (integer) - Optional - Output at most COLUMNS (default 130) print columns per line. - **-W, --ignore-all-space** (flag) - Optional - Ignore white space when comparing lines. - **-Z, --ignore-trailing-space** (flag) - Optional - Ignore white space at line end. ``` -------------------------------- ### GNU diff3 Options Summary Source: https://www.gnu.org/software/diffutils/manual/html_node/diff3-Options.html This section provides a detailed breakdown of each option available for the `diff3` command, including their short and long forms, and their specific functionalities. ```APIDOC ## GNU diff3 Options This document summarizes all options that GNU `diff3` accepts. Multiple single-letter options (unless they take an argument) can be combined. ### -a, --text Treat all files as text and compare them line-by-line, even if they do not appear to be text. ### -A, --show-all Incorporate all unmerged changes from older to yours into mine, surrounding conflicts with bracket lines. ### --diff-program=program Use the compatible comparison program `program` to compare files instead of `diff`. ### -e, --ed Generate an `ed` script that incorporates all the changes from older to yours into mine. ### -E, --show-overlap Like -e, except bracket lines from overlapping changes’ first and third files. With -E, an overlapping change looks like this: ``` <<<<<<< mine lines from mine ======= lines from yours >>>>>>> yours ``` ### --help Output a summary of usage and then exit. ### -i Generate ‘w’ and ‘q’ commands at the end of the `ed` script for System V compatibility. This option must be combined with one of the -AeExX3 options, and may not be combined with -m. ### --label=label Use the label `label` for the brackets output by the -A, -E and -X options. This option may be given up to three times, one for each input file. The default labels are the names of the input files. ### -m, --merge Apply the edit script to the first file and send the result to standard output. Unlike piping the output from `diff3` to `ed`, this works even for binary files and incomplete lines. -A is assumed if no edit script option is specified. ### --strip-trailing-cr Strip any trailing carriage return at the end of an input line. ### -T, --initial-tab Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to look normal. ### -v, --version Output version information and then exit. ### -x, --overlap-only Like -e, except output only the overlapping changes. ### -X Like -E, except output only the overlapping changes. In other words, like -x, except bracket changes as in -E. ### -3, --easy-only Like -e, except output only the nonoverlapping changes. ``` -------------------------------- ### Exclude Multiple Patterns from Directory Comparison Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Specify multiple '-x' options to exclude files matching different patterns. This example ignores 'RCS' files and files ending with ',v'. ```bash diff -x 'RCS' -x '*,v' directory1 directory2 ``` -------------------------------- ### Portable patch command-line options Source: https://www.gnu.org/software/diffutils/manual/html_node/patch-and-Tradition.html A list of options that maintain compatibility across GNU patch, traditional patch, and POSIX-compliant patch implementations. ```text -c -d dir -D define -e -l -n -N -o outfile -pnum -R -r rejectfile ``` -------------------------------- ### Formatting Line Numbers with printf Source: https://www.gnu.org/software/diffutils/manual/diffutils.txt Formats a line number using a printf conversion specification. For example, '%.5dn' formats the line number to occupy at least 5 characters, padded with spaces. ```bash Fn ``` -------------------------------- ### Use a Different Comparison Program Source: https://www.gnu.org/software/diffutils/manual/html_node/diff3-Options.html The --diff-program=program option allows you to specify an alternative comparison program to be used instead of the default `diff`. This provides flexibility in choosing the underlying diff algorithm. ```bash diff3 --diff-program=my_diff_program file1 file2 file3 ```