From 00344431402703089c6b93f6119f9966cc7ba566 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 31 Jul 2001 23:18:49 +0000 Subject: [PATCH] Fix behavior of grep -lc to match GNU grep. SuS2 is ambiguous on the correct behavior, so acting like GNU grep seems best -Erik --- findutils/grep.c | 5 ++++- grep.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/findutils/grep.c b/findutils/grep.c index 03cc9f836..3254868be 100644 --- a/findutils/grep.c +++ b/findutils/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 */ diff --git a/grep.c b/grep.c index 03cc9f836..3254868be 100644 --- 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 */ -- 2.25.1