📄 diff.texi
字号:
and @file{new}, and outputs a merged file in which old regions aresurrounded by @samp{\begin@{em@}}-@samp{\end@{em@}} lines, and newregions are surrounded by @samp{\begin@{bf@}}-@samp{\end@{bf@}} lines.@examplediff \ --old-group-format='\begin@{em@}%<\end@{em@}' \ --new-group-format='\begin@{bf@}%>\end@{bf@}' \ old new@end exampleThe following command is equivalent to the above example, but it is alittle more verbose, because it spells out the default line group formats.@examplediff \ --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@end exampleHere is a more advanced example, which outputs a diff listing withheaders containing line numbers in a ``plain English'' style.@examplediff \ --unchanged-group-format='' \ --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:%<' \ --new-group-format='-------- %dN line%(N=1?:s) added after %de:%>' \ --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:%<-------- to:%>' \ old new@end exampleTo specify a line group format, use @command{diff} with one of the optionslisted below. You can specify up to four line group formats, one foreach kind of line group. You should quote @var{format}, because ittypically contains shell metacharacters.@table @option@item --old-group-format=@var{format}These line groups are hunks containing only lines from the first file.The default old group format is the same as the changed group format ifit is specified; otherwise it is a format that outputs the line group as-is.@item --new-group-format=@var{format}These line groups are hunks containing only lines from the secondfile. The default new group format is same as the changed groupformat if it is specified; otherwise it is a format that outputs theline group as-is.@item --changed-group-format=@var{format}These line groups are hunks containing lines from both files. Thedefault changed group format is the concatenation of the old and newgroup formats.@item --unchanged-group-format=@var{format}These line groups contain lines common to both files. The defaultunchanged group format is a format that outputs the line group as-is.@end tableIn a line group format, ordinary characters represent themselves;conversion specifications start with @samp{%} and have one of thefollowing forms.@table @samp@item %<stands for the lines from the first file, including the trailing newline.Each line is formatted according to the old line format (@pxref{Line Formats}).@item %>stands for the lines from the second file, including the trailing newline.Each line is formatted according to the new line format.@item %=stands for the lines common to both files, including the trailing newline.Each line is formatted according to the unchanged line format.@item %%stands for @samp{%}.@item %c'@var{C}'where @var{C} is a single character, stands for @var{C}.@var{C} may not be a backslash or an apostrophe.For example, @samp{%c':'} stands for a colon, even insidethe then-part of an if-then-else format, which a colon wouldnormally terminate.@item %c'\@var{O}'where @var{O} is a string of 1, 2, or 3 octal digits,stands for the character with octal code @var{O}.For example, @samp{%c'\0'} stands for a null character.@item @var{F}@var{n}where @var{F} is a @code{printf} conversion specification and @var{n} is oneof the following letters, stands for @var{n}'s value formatted with @var{F}.@table @samp@item eThe line number of the line just before the group in the old file.@item fThe line number of the first line in the group in the old file;equals @var{e} + 1.@item lThe line number of the last line in the group in the old file.@item mThe line number of the line just after the group in the old file;equals @var{l} + 1.@item nThe number of lines in the group in the old file; equals @var{l} - @var{f} + 1.@item E, F, L, M, NLikewise, for lines in the new file.@end table@vindex LC_NUMERICThe @code{printf} conversion specification can be @samp{%d},@samp{%o}, @samp{%x}, or @samp{%X}, specifying decimal, octal,lower case hexadecimal, or upper case hexadecimal outputrespectively. After the @samp{%} the following options can appear insequence: a series of zero or more flags; an integerspecifying the minimum field width; and a period followed by anoptional integer specifying the minimum number of digits.The flags are @samp{-} for left-justification, @samp{'} for separatingthe digit into groups as specified by the @env{LC_NUMERIC} locale category,and @samp{0} for padding with zeros instead of spaces.For example, @samp{%5dN} prints the number of new lines in the groupin a field of width 5 characters, using the @code{printf} format @code{"%5d"}.@item (@var{A}=@var{B}?@var{T}:@var{E})If @var{A} equals @var{B} then @var{T} else @var{E}.@var{A} and @var{B} are each either a decimal constantor a single letter interpreted as above.This format spec is equivalent to @var{T} if@var{A}'s value equals @var{B}'s; otherwise it is equivalent to @var{E}.For example, @samp{%(N=0?no:%dN) line%(N=1?:s)} is equivalent to@samp{no lines} if @var{N} (the number of lines in the group in thenew file) is 0, to @samp{1 line} if @var{N} is 1, and to @samp{%dN lines}otherwise.@end table@node Line Formats@subsection Line Formats@cindex line formatsLine formats control how each line taken from an input file isoutput as part of a line group in if-then-else format.For example, the following command outputs text with a one-characterchange indicator to the left of the text. The first character of outputis @samp{-} for deleted lines, @samp{|} for added lines, and a space forunchanged lines. The formats contain newline characters where newlinesare desired on output.@examplediff \ --old-line-format='-%l' \ --new-line-format='|%l' \ --unchanged-line-format=' %l' \ old new@end exampleTo specify a line format, use one of the following options. You shouldquote @var{format}, since it often contains shell metacharacters.@table @option@item --old-line-format=@var{format}formats lines just from the first file.@item --new-line-format=@var{format}formats lines just from the second file.@item --unchanged-line-format=@var{format}formats lines common to both files.@item --line-format=@var{format}formats all lines; in effect, it sets all three above options simultaneously.@end tableIn a line format, ordinary characters represent themselves;conversion specifications start with @samp{%} and have one of thefollowing forms.@table @samp@item %lstands for the contents of the line, not counting its trailingnewline (if any). This format ignores whether the line is incomplete;@xref{Incomplete Lines}.@item %Lstands for the contents of the line, including its trailing newline(if any). If a line is incomplete, this format preserves itsincompleteness.@item %%stands for @samp{%}.@item %c'@var{C}'where @var{C} is a single character, stands for @var{C}.@var{C} may not be a backslash or an apostrophe.For example, @samp{%c':'} stands for a colon.@item %c'\@var{O}'where @var{O} is a string of 1, 2, or 3 octal digits,stands for the character with octal code @var{O}.For example, @samp{%c'\0'} stands for a null character.@item @var{F}nwhere @var{F} is a @code{printf} conversion specification,stands for the line number formatted with @var{F}.For example, @samp{%.5dn} prints the line number using the@code{printf} format @code{"%.5d"}. @xref{Line Group Formats}, formore about printf conversion specifications.@end tableThe default line format is @samp{%l} followed by a newline character.If the input contains tab characters and it is important that they lineup on output, you should ensure that @samp{%l} or @samp{%L} in a lineformat is just after a tab stop (e.g.@: by preceding @samp{%l} or@samp{%L} with a tab character), or you should use the @option{-t} or@option{--expand-tabs} option.Taken together, the line and line group formats let you specify manydifferent formats. For example, the following command uses a formatsimilar to normal @command{diff} format. You can tailor this commandto get fine control over @command{diff} output.@examplediff \ --old-line-format='< %l' \ --new-line-format='> %l' \ --old-group-format='%df%(f=l?:,%dl)d%dE%<' \ --new-group-format='%dea%dF%(F=L?:,%dL)%>' \ --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)%<---%>' \ --unchanged-group-format='' \ old new@end example@node Example If-then-else@subsection An Example of If-then-else FormatHere is the output of @samp{diff -DTWO lao tzu} (@pxref{Samplediff Input}, for the complete contents of the two files):@example#ifndef TWOThe Way that can be told of is not the eternal Way;The name that can be named is not the eternal name.#endif /* ! TWO */The Nameless is the origin of Heaven and Earth;#ifndef TWOThe Named is the mother of all things.#else /* TWO */The named is the mother of all things.#endif /* TWO */Therefore let there always be non-being, so we may see their subtlety,And let there always be being, so we may see their outcome.The two are the same,But after they are produced, they have different names.#ifdef TWOThey both may be called deep and profound.Deeper and more profound,The door of all subtleties!#endif /* TWO */@end example@node Detailed If-then-else@subsection Detailed Description of If-then-else FormatFor lines common to both files, @command{diff} uses the unchanged linegroup format. For each hunk of differences in the merged outputformat, if the hunk contains only lines from the first file,@command{diff} uses the old line group format; if the hunk contains onlylines from the second file, @command{diff} uses the new group format;otherwise, @command{diff} uses the changed group format.The old, new, and unchanged line formats specify the output format oflines from the first file, lines from the second file, and lines commonto both files, respectively.The option @option{--ifdef=@var{name}} is equivalent tothe following sequence of options using shell syntax:@example--old-group-format='#ifndef @var{name}%<#endif /* ! @var{name} */' \--new-group-format='#ifdef @var{name}%>#endif /* @var{name} */' \--unchanged-group-format='%=' \--changed-group-format='#ifndef @var{name}%<#else /* @var{name} */%>#endif /* @var{name} */'@end exampleYou should carefully check the @command{diff} output for proper nesting.For example, when using the @option{-D @var{name}} or@op
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -