Bob
Bob

Reputation: 1679

windows grep regex not working

Windows 10.

grep installed as part of git installation.

>grep --version

grep (GNU grep) 2.27
Copyright (C) 2016 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>.

>git --version

git version 2.12.0.windows.1

File sample.txt created with notepad contains the following 3 lines;

a
b
c

Get grep to return lines starting with 'a' or 'c' ;

>grep ^[ac].*$ sample.txt
a
c

(OK - as expected)

Get grep to return lines starting with any char except 'a' or 'c' i.e. the line starting with 'b' ;

>grep ^[^ac].*$ sample.txt
a
c

why is this not working ?

Upvotes: 1

Views: 1874

Answers (1)

Alex K.
Alex K.

Reputation: 175816

At the command line ^ is used to indicate an escape (i.e. ^| is treated as as literal | as opposed to a command pipe).

To escape the escape double it so: ^^[^^ac ...

Upvotes: 1

Related Questions