From b50a151346c42816034b5c26266eb753b7dbe737 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Tue, 22 Nov 2016 22:03:47 +0100 Subject: comm: add --total option * src/comm.c (total_option): Add bool variable for the new option. (TOTAL_OPTION): Add enum value. (long_options): Add array element for the new option. (usage): Document the new option here. (compare_files): Count the lines in total[3], and output the summary at the end. (main): Accept the new option. * doc/coreutils.texi (comm invocation): Document it. * tests/misc/comm.pl: Test it. While at it, improve the test data to have 1 unique line in the first file, 2 unique lines in the second file, and 3 common lines. * NEWS (New Features): Mention the new option. Fixes http://bugs.gnu.org/24929 --- doc/coreutils.texi | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'doc') diff --git a/doc/coreutils.texi b/doc/coreutils.texi index d0694fdd0..521ac3923 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -5174,6 +5174,37 @@ rather than the default of a single TAB character. The delimiter @var{str} may not be empty. +@item --total +Output a summary at the end. + +Similar to the regular output, +column one contains the total number of lines unique to @var{file1}, +column two contains the total number of lines unique to @var{file2}, and +column three contains the total number of lines common to both files, +followed by the word @samp{total} in the additional column four. + +In the following example, @command{comm} omits the regular output +(@option{-123}), thus just printing the summary: + +@example +$ printf '%s\n' a b c d e > file1 +$ printf '%s\n' b c d e f g > file2 +$ comm --total -123 file1 file2 +1 2 4 total +@end example + +This option is a GNU extension. Portable scripts should use @command{wc} to +get the totals, e.g. for the above example files: + +@example +$ comm -23 file1 file2 | wc -l # number of lines only in file1 +1 +$ comm -13 file1 file2 | wc -l # number of lines only in file2 +2 +$ comm -12 file1 file2 | wc -l # number of lines common to both files +4 +@end example + @optZeroTerminated @end table -- cgit v1.2.3-54-g00ecf