0
Here is a file I have http://www.zen76171.zen.co.uk/blahsomefile1
It's a text file about 1.18MB in size
Looking at how many matching lines I get
With -P
C:\blah>grep -P "[^J]*J" blahsomefile1 | wc -l
72383
Without -P
C:\blah>grep "[^J]*J" blahsomefile1 | wc -l
51814
There shouldn't be a difference whether -P or without -P, but there is. The -P is matching too much.
With this test I should get the same figure 'cos i'm saying list every line that matches xyz and within that output list every line that matches xyz. It works without -P.
Without -P nothing funny happening.
C:\blah>grep "[^J]*J" blahsomefile1 | wc -l
51814
C:\blah>grep "[^J]*J" blahsomefile1 | grep "[^J]*J" | wc -l
51814
With -P things happening that should not be happening..
C:\blah>grep -P "[^J]*J" blahsomefile1 | wc -l
72383
C:\blah>grep -P "[^J]*J" blahsomefile1 | grep -P "[^J]*J" | wc -l
72229
If I do grep -P "[^J]*J" blahsomefile1 | more
I see it is matching things it shouldn't match, like the line that reads txxxraabcAA
which contains no J.
txxxJbmmabcraabc
txxxraabcAA
txxxJxmmabcHaabc
Computer is running gnuwin32 grep
C:\blah>where grep
C:\Program Files (x86)\GnuWin32\bin\grep.exe
grep version is 2.5.4
C:\blah>"C:\Program Files (x86)\GnuWin32\bin\grep.exe" -V
GNU grep 2.5.4
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
C:\blah>
UPDATE
Interestingly cygwin's one is much later.. and doesn't have the bug
C:\blah\aeea2\a\a\a\a>c:\cygwin\bin\grep -P "[^J]*J" blahsomefile1 | wc -l
51814
C:\blah>c:\cygwin\bin\grep -V
/usr/bin/grep (GNU grep) 2.21
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
C:\blah>
gnuwin32 grep is still on 2.5.4 , a very old version.
Note- file is also available from wetransfer and downloadable from ge.tt with eg firefox.
1
I cannot reproduce this problem on Linux using the current version of GNU grep: 2.26. You may want to see if you can update your software: version 2.5.4 dates to 2009
– John1024 – 2016-10-17T02:43:33.683