Fix behavior of grep -lc to match GNU grep. SuS2 is ambiguous
authorEric Andersen <andersen@codepoet.org>
Tue, 31 Jul 2001 23:18:49 +0000 (23:18 -0000)
committerEric Andersen <andersen@codepoet.org>
Tue, 31 Jul 2001 23:18:49 +0000 (23:18 -0000)
on the correct behavior, so acting like GNU grep seems best
 -Erik

findutils/grep.c
grep.c

index 03cc9f836dbed6cb80cd55d5979e9271f7708976..3254868be1672e03e045c4b8f1e7b47fac9af580 100644 (file)
@@ -179,7 +179,10 @@ static void grep_file(FILE *file)
        if (print_match_counts) {
                if (print_filename)
                        printf("%s:", cur_file);
-               printf("%d\n", nmatches);
+               if (print_files_with_matches && nmatches > 0)
+                       printf("1\n");
+               else
+                   printf("%d\n", nmatches);
        }
 
        /* grep -l: print just the filename, but only if we grepped the line in the file  */
diff --git a/grep.c b/grep.c
index 03cc9f836dbed6cb80cd55d5979e9271f7708976..3254868be1672e03e045c4b8f1e7b47fac9af580 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -179,7 +179,10 @@ static void grep_file(FILE *file)
        if (print_match_counts) {
                if (print_filename)
                        printf("%s:", cur_file);
-               printf("%d\n", nmatches);
+               if (print_files_with_matches && nmatches > 0)
+                       printf("1\n");
+               else
+                   printf("%d\n", nmatches);
        }
 
        /* grep -l: print just the filename, but only if we grepped the line in the file  */