Line group formats let you specify formats suitable for many applications that allow if-then-else input, including programming languages and text formatting languages. A line group format specifies the output format for a contiguous group of similar lines.
For example, the following command compares the TeX files `old' and `new', and outputs a merged file in which old regions are surrounded by `\begin{em}'-`\end{em}' lines, and new regions are surrounded by `\begin{bf}'-`\end{bf}' lines.
diff \
--old-group-format='\begin{em}
%<\end{em}
' \
--new-group-format='\begin{bf}
%>\end{bf}
' \
old new
The following command is equivalent to the above example, but it is a little more verbose, because it spells out the default line group formats.
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
Here is a more advanced example, which outputs a diff listing with headers containing line numbers in a "plain English" style.
diff \ --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
To specify a line group format, use diff with one of the options
listed below. You can specify up to four line group formats, one for
each kind of line group. You should quote format, because it
typically contains shell metacharacters.
In a line group format, ordinary characters represent themselves; conversion specifications start with `%' and have one of the following forms.
printf conversion specification and n is one
of the following letters, stands for n's value formatted with F.
printf conversion specification can be `%d',
`%o', `%x', or `%X', specifying decimal, octal,
lower case hexadecimal, or upper case hexadecimal output
respectively. After the `%' the following options can appear in
sequence: a `-' specifying left-justification; an integer
specifying the minimum field width; and a period followed by an
optional integer specifying the minimum number of digits.
For example, `%5dN' prints the number of new lines in the group
in a field of width 5 characters, using the printf format "%5d".
Go to the first, previous, next, last section, table of contents.