-.\" $OpenBSD: grep.1,v 1.52 2023/01/04 07:33:00 jmc Exp $
+.\" $OpenBSD: grep.1,v 1.53 2023/11/15 00:50:43 millert Exp $
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\"
.\" @(#)grep.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: January 4 2023 $
+.Dd $Mdocdate: November 15 2023 $
.Dt GREP 1
.Os
.Sh NAME
.Dq (standard input)
is written.
.It Fl m Ar num
-Stop after
+Stop after finding at least one match on
.Ar num
-matches.
+different lines.
.It Fl n
Each output line is preceded by its relative line number in the file,
starting at line 1.
-/* $OpenBSD: util.c,v 1.67 2022/07/12 18:09:31 op Exp $ */
+/* $OpenBSD: util.c,v 1.68 2023/11/15 00:50:43 millert Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
procline(str_t *l, int nottext)
{
regmatch_t pmatch = { 0 };
- int c, i, r;
+ int c, i, r, counted;
regoff_t offset;
/* size_t will be converted to regoff_t. ssize_t is guaranteed to fit
c = 0;
i = 0;
+ counted = 0;
if (matchall) {
c = 1;
goto print;
if (vflag)
c = !c;
- /* Count the matches if we have a match limit */
- if (mflag)
+ /* Count the matches if there is a match limit (but only once). */
+ if (mflag && !counted) {
mcount -= c;
+ counted = 1;
+ }
if (c && binbehave == BIN_FILE_BIN && nottext)
return c; /* Binary file */