# HG changeset patch # User Rob Landley # Date 1376295389 18000 # Node ID 8b49ff103af9b4c80c280bbc0e4d866807d21f58 # Parent 99dad9fb56131fbdddf58b754fe6eef5439beeee grep: -om counts matching lines, not matching parts of lines. diff -r 99dad9fb5613 -r 8b49ff103af9 toys/pending/grep.c --- a/toys/pending/grep.c Mon Aug 12 03:08:56 2013 -0500 +++ b/toys/pending/grep.c Mon Aug 12 03:16:29 2013 -0500 @@ -67,6 +67,7 @@ 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 @@ matches[which].rm_so = 0; } else if (rc) break; - mcount++; + mmatch++; if (toys.optflags & FLAG_q) { toys.exitval = 0; xexit(); @@ -152,6 +153,7 @@ free(line); + if (mmatch) mcount++; if ((toys.optflags & FLAG_m) && mcount >= TT.m) break; }