From 030970bd70e14849b0f2598bfa0982402fc7e2e7 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 12 Aug 2013 03:16:29 -0500 Subject: grep: -om counts matching lines, not matching parts of lines. --- toys/pending/grep.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'toys/pending/grep.c') diff --git a/toys/pending/grep.c b/toys/pending/grep.c index 215c6d24..9c282ea7 100644 --- a/toys/pending/grep.c +++ b/toys/pending/grep.c @@ -67,6 +67,7 @@ static void do_grep(int fd, char *name) regmatch_t matches[3]; size_t unused; long len; + int mmatch = 0; lcount++; if (0 > (len = getline(&line, &unused, file))) break; @@ -121,7 +122,7 @@ static void do_grep(int fd, char *name) matches[which].rm_so = 0; } else if (rc) break; - mcount++; + mmatch++; if (toys.optflags & FLAG_q) { toys.exitval = 0; xexit(); @@ -152,6 +153,7 @@ static void do_grep(int fd, char *name) free(line); + if (mmatch) mcount++; if ((toys.optflags & FLAG_m) && mcount >= TT.m) break; } -- cgit v1.2.3