Sample Header Ad - 728x90

Does pcregrep (or pcre2grep) have the equivalent of grep's --max-count option?

1 vote
1 answer
624 views
Take the following file :
aaa
bbb
XXX
ccc
ddd
eee
XXX
fff
ggg
I'd like to print, **with pcregrep**, all lines until the first one containing XXX :
aaa
bbb
XXX
Is it possible (with pcregrep or pcre2grep) ? I achieved this :
$ pcre2grep -nM '(.|\n)*?XXX' file
1:aaa
bbb
XXX
4:ccc
ddd
eee
XXX
Is there a way to quit after the first match ? It seems that pcre2grep doesn't have a --max-count option like grep has. Nota : I'm aware that there are better tools to get the desired result (sed, among others), but I'm not looking for alternate solutions here. My question is about pcregrep or pcre2grep, I'd like to know if there is a way to emulate grep's --max-count option.
Asked by ChennyStar (1969 rep)
Oct 16, 2021, 03:05 PM
Last activity: Oct 17, 2021, 01:34 PM