> I have a file (example.txt) that contains the following six lines:
> something else
> /Type /Pages
> /Type /Page
> /Type /Page >>
> /Type /Page/Foo
> something else
>
> When I run the following in a cmd shell on XP using GnuWin's port of grep 
> 2.51, I expect the result 3 but
> instead get 0:
>  grep  --count "/Type /Page[^s]" example.txt
> 0

The result I get, with grep-2.5.1a under XP, is: 2, both directly in a cmd 
shell and through a bat file. This, and not 3, is also the correct answer, 
because the regular expression "/Type /Page[^s]" requires at least one more 
character after "Page", and in the line "/Type /Page", there is no 
additional character.

> When I run the same command in cygwin with cygwin's port of grep 2.51, I 
> do get the expected result.

You get this result because there is indeed an additional character, 0xD, 
before the line ending (0xA). Remenber: under Cygwin, the default is binary 
files, whereas under MS-Windows, 0xD0xA is the line ending. If you remove 
the 0xD's from example.txt, then you get the same result as above: 2.

What you want can be achieved by:

    grep --count -E "/Type /Page([^s]|$)" example.txt

which gives the result: 3

Kees Zeelenberg 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
GnuWin32-Users mailing list
GnuWin32-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gnuwin32-users

Reply via email to