[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug #25765] grep -P regexp also prints the line before the match
From: |
Wacek Kusnierczyk |
Subject: |
Re: [bug #25765] grep -P regexp also prints the line before the match |
Date: |
Thu, 05 Mar 2009 18:34:47 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20090105) |
Andriy Sen wrote:
> Hmm...
>
> My problem seem to come from the fact "^" matches not only beginning
> of the current line but beginning of any of the previous lines so
> instead of "^.*" I need to do "^[^\n]*". If that is not considered a
> bug than the documentation definitely needs updating...
the issue is not that grep -P includes previous lines, but that it
matches across multiple lines. grep -P works (seems to work) like perl
in multiline mode, where '^' matches at the beginning of each line, not
just the beginning of the input text:
printf "a\n1\n" | grep -nP '^[^^]+'
# one match spanning the whole file
perl -le 'print "match: $_" foreach "a\n1\n" =~ /(^[^^]+)/m'
# one match spanning the whole file
printf "a\n1\n" | grep -nzP '^[^^]'
# two matches
perl -le 'print "match: $_" foreach "a\n1\n" =~ /(^[^^])/mg'
# two matches
vQ