[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 08:21:18 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20090105) |
Andriy Sen wrote:
> See tree examples below. The last one shows the problem.
>
>
> G:\>cat test.s
> a
> 1
>
> G:\>od -a test.s
> 0000000 a nl 1 nl
> 0000004
>
> G:\>cat test.s | grep -P "^[^0]1"
>
>
> G:\>cat test.s | grep -P "^(|[^0])1"
> 1
>
> G:\>cat test.s | grep -P "^(|.*[^0])1"
> a
> 1
>
>
what problem?
cat test.s | grep -Pn "^(|.*[^0])1"
# 1:a
# 1
as you can see, there is one match here. '.*' matches 'a', and '[^0]'
matches the newline. and so '1' can match '1'. there is no 'line
before the match'; the line before that containing '1' is *within* the
match.
vQ