Given after-context=3 it is expected to output at least 4 lines as documented, but adding max-count=1 makes it stop on the next matching line.
Thanks for reporting this. Although grep's behavior is documented ("context does not include matching lines" in the node General Output Control) the documentation could be clearer and I installed the attached patch.
From 90a2dd8b7f93ef0a8f08741e6fcb07220f9549f6 Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> Date: Wed, 7 Sep 2016 22:22:37 -0700 Subject: [PATCH] doc: define "context lines" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by Igor Bogomazov via Santiago Ruano Rincón (Bug#24024). * doc/grep.texi (Context Line Control): Define "context lines". --- doc/grep.texi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/grep.texi b/doc/grep.texi index 80768dd..7e51d45 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -338,6 +338,7 @@ do done @end example +@cindex context lines When @command{grep} stops after @var{num} matching lines, it outputs any trailing context lines. Since context does not include matching lines, @@ -501,8 +502,11 @@ even those that contain newline characters. @node Context Line Control @subsection Context Line Control +@cindex context lines +@dfn{Context lines} are non-matching lines that are near a matching line. +They are output only if one of the following options are used. Regardless of how these options are set, -@command{grep} will never print any given line more than once. +@command{grep} never outputs any given line more than once. If the @option{-o} (@option{--only-matching}) option is specified, these options have no effect and a warning is given upon their use. @@ -530,7 +534,7 @@ Print @var{num} lines of leading context before matching lines. @opindex -C @opindex --context @opindex -@var{num} -@cindex context +@cindex context lines Print @var{num} lines of leading and trailing output context. @item --group-separator=@var{string} -- 2.7.4