On 11/18/2016 10:43 PM, 積丹尼 Dan Jacobson wrote:
> The example is confusing, as it just happens to result in 1 2 3,
> 
> $ printf '%s\n' 1 2 3 4     > file1
> $ printf '%s\n'   2 3 4 5 6 > file2
> $ comm --total -123 file1 file2
> 1       2       3       total
> 
> So please use
> 
> $ printf '%s\n' 0   2 3   5 6       > file1
> $ printf '%s\n'   1 2   4   6 7 8 9 > file2
> $ comm --total -123 file1 file2
> 3       5       2      total

I see the point. I changed the example data to 'a b c ...' which I think
is even easier to read and understand.

> Also add a note "However --total is a GNU extension. For a portable way
> to make totals, use wc:
> 
> $ echo Lines only in 1st = $(comm -23 file1 file2 | wc -l)
> $ echo Lines only in 2nd = $(comm -13 file1 file2 | wc -l)
> $ echo Lines in both =     $(comm -12 file1 file2 | wc -l)

I'll squash in the attached, and push soon.

Thanks & have a nice day,
Berny
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 21fa2be..b0c13b9 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -5147,14 +5147,32 @@ 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' 1 2 3 4     > file1
-$ printf '%s\n'   2 3 4 5 6 > file2
+$ 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       3       total
+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

Reply via email to