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



Reply via email to