Cygwin unexpected token `(' with grep
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am using Cygwin on Windows 7 OS.
I am trying to match an email of this format: x.y@enron.com
This is my regex:
grep [a-zA-Z0-9]+.[a-zA-Z0-9]+@(E|e)nron.com
it returns
-bash: syntax error near unexpected token `('
It works when used in regex101.com
It should match emails like a.z@enron.com
and ros.cab@Enron.com
bash shell command-line
 |Â
show 3 more comments
up vote
1
down vote
favorite
I am using Cygwin on Windows 7 OS.
I am trying to match an email of this format: x.y@enron.com
This is my regex:
grep [a-zA-Z0-9]+.[a-zA-Z0-9]+@(E|e)nron.com
it returns
-bash: syntax error near unexpected token `('
It works when used in regex101.com
It should match emails like a.z@enron.com
and ros.cab@Enron.com
bash shell command-line
4
How are you using it? It should be single quoted to avoid shell keywords from being parsed.
â jordanm
May 8 at 13:58
it doesn't match when i single quote it
â Andres ZW
May 8 at 14:00
1
@AndresZW: Does it match when it errors? Are you usinggrep -E
?
â Jesse_b
May 8 at 14:08
1
Again, how are you using it? Is it ingrep -Ex that-regex somefile
, in[[ $string =~ that-regex ]]
? What version of bash?
â Stéphane Chazelas
May 8 at 14:09
1
Please edit your question using the "edit" link and include the exact code you're using and what you expect it do do.
â Stéphane Chazelas
May 8 at 14:42
 |Â
show 3 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using Cygwin on Windows 7 OS.
I am trying to match an email of this format: x.y@enron.com
This is my regex:
grep [a-zA-Z0-9]+.[a-zA-Z0-9]+@(E|e)nron.com
it returns
-bash: syntax error near unexpected token `('
It works when used in regex101.com
It should match emails like a.z@enron.com
and ros.cab@Enron.com
bash shell command-line
I am using Cygwin on Windows 7 OS.
I am trying to match an email of this format: x.y@enron.com
This is my regex:
grep [a-zA-Z0-9]+.[a-zA-Z0-9]+@(E|e)nron.com
it returns
-bash: syntax error near unexpected token `('
It works when used in regex101.com
It should match emails like a.z@enron.com
and ros.cab@Enron.com
bash shell command-line
edited May 8 at 15:28
ilkkachu
48.2k669133
48.2k669133
asked May 8 at 13:56
Andres ZW
84
84
4
How are you using it? It should be single quoted to avoid shell keywords from being parsed.
â jordanm
May 8 at 13:58
it doesn't match when i single quote it
â Andres ZW
May 8 at 14:00
1
@AndresZW: Does it match when it errors? Are you usinggrep -E
?
â Jesse_b
May 8 at 14:08
1
Again, how are you using it? Is it ingrep -Ex that-regex somefile
, in[[ $string =~ that-regex ]]
? What version of bash?
â Stéphane Chazelas
May 8 at 14:09
1
Please edit your question using the "edit" link and include the exact code you're using and what you expect it do do.
â Stéphane Chazelas
May 8 at 14:42
 |Â
show 3 more comments
4
How are you using it? It should be single quoted to avoid shell keywords from being parsed.
â jordanm
May 8 at 13:58
it doesn't match when i single quote it
â Andres ZW
May 8 at 14:00
1
@AndresZW: Does it match when it errors? Are you usinggrep -E
?
â Jesse_b
May 8 at 14:08
1
Again, how are you using it? Is it ingrep -Ex that-regex somefile
, in[[ $string =~ that-regex ]]
? What version of bash?
â Stéphane Chazelas
May 8 at 14:09
1
Please edit your question using the "edit" link and include the exact code you're using and what you expect it do do.
â Stéphane Chazelas
May 8 at 14:42
4
4
How are you using it? It should be single quoted to avoid shell keywords from being parsed.
â jordanm
May 8 at 13:58
How are you using it? It should be single quoted to avoid shell keywords from being parsed.
â jordanm
May 8 at 13:58
it doesn't match when i single quote it
â Andres ZW
May 8 at 14:00
it doesn't match when i single quote it
â Andres ZW
May 8 at 14:00
1
1
@AndresZW: Does it match when it errors? Are you using
grep -E
?â Jesse_b
May 8 at 14:08
@AndresZW: Does it match when it errors? Are you using
grep -E
?â Jesse_b
May 8 at 14:08
1
1
Again, how are you using it? Is it in
grep -Ex that-regex somefile
, in [[ $string =~ that-regex ]]
? What version of bash?â Stéphane Chazelas
May 8 at 14:09
Again, how are you using it? Is it in
grep -Ex that-regex somefile
, in [[ $string =~ that-regex ]]
? What version of bash?â Stéphane Chazelas
May 8 at 14:09
1
1
Please edit your question using the "edit" link and include the exact code you're using and what you expect it do do.
â Stéphane Chazelas
May 8 at 14:42
Please edit your question using the "edit" link and include the exact code you're using and what you expect it do do.
â Stéphane Chazelas
May 8 at 14:42
 |Â
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
[
, ,
(
and )
all have special meanings to the shell and should be quoted if you intend to pass them verbatim in an argument to a command (here grep
).
Also note that ranges like [a-z]
make little sense outside of the C locale.
So here, you probably want:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@(E|e)nron.com' < some-file
Or:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@[Ee]nron.com' < some-file
To report the lines that match that E
xtended regular expression ex
actly. With the al
phanum
erical characters limited to those of the C
locale (so on Cygwin, ASCII English/latin letters without diacritics and Arabic decimal digits; in the C locale [[:alnum:]]
and [a-zA-Z0-9]
match the same thing).
Above using the '...'
form of quoting that is the strongest one (no character is special within them).
+
, |
, (...)
are extended regexp operator (not basic regexp operators as expected by grep
without -E
). Without -x
, grep
would look for matches within the lines, so for example would match on a line like:
foo@bar.com x.y.z@enron.common.br whatever
^^^^^^^^^^^^^
Without LC_ALL=C
, [[:alnum:]]
could match on characters of other alphetical scripts (like the Greek, Cyrillic, Korean ones), and [a-z]
could match on some latin characters with diacritics like á
, ç
, ÿ
but not others like áºÂ
, Ã
º
as they come after z
...
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
@AndresZW, add-v
to report the lines that don't match.
â Stéphane Chazelas
May 8 at 15:18
@AndresZW, see edit aboutLC_ALL=C
. I'd say it's the most minor of the problems in your original code.
â Stéphane Chazelas
May 8 at 15:20
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
[
, ,
(
and )
all have special meanings to the shell and should be quoted if you intend to pass them verbatim in an argument to a command (here grep
).
Also note that ranges like [a-z]
make little sense outside of the C locale.
So here, you probably want:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@(E|e)nron.com' < some-file
Or:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@[Ee]nron.com' < some-file
To report the lines that match that E
xtended regular expression ex
actly. With the al
phanum
erical characters limited to those of the C
locale (so on Cygwin, ASCII English/latin letters without diacritics and Arabic decimal digits; in the C locale [[:alnum:]]
and [a-zA-Z0-9]
match the same thing).
Above using the '...'
form of quoting that is the strongest one (no character is special within them).
+
, |
, (...)
are extended regexp operator (not basic regexp operators as expected by grep
without -E
). Without -x
, grep
would look for matches within the lines, so for example would match on a line like:
foo@bar.com x.y.z@enron.common.br whatever
^^^^^^^^^^^^^
Without LC_ALL=C
, [[:alnum:]]
could match on characters of other alphetical scripts (like the Greek, Cyrillic, Korean ones), and [a-z]
could match on some latin characters with diacritics like á
, ç
, ÿ
but not others like áºÂ
, Ã
º
as they come after z
...
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
@AndresZW, add-v
to report the lines that don't match.
â Stéphane Chazelas
May 8 at 15:18
@AndresZW, see edit aboutLC_ALL=C
. I'd say it's the most minor of the problems in your original code.
â Stéphane Chazelas
May 8 at 15:20
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
 |Â
show 1 more comment
up vote
2
down vote
accepted
[
, ,
(
and )
all have special meanings to the shell and should be quoted if you intend to pass them verbatim in an argument to a command (here grep
).
Also note that ranges like [a-z]
make little sense outside of the C locale.
So here, you probably want:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@(E|e)nron.com' < some-file
Or:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@[Ee]nron.com' < some-file
To report the lines that match that E
xtended regular expression ex
actly. With the al
phanum
erical characters limited to those of the C
locale (so on Cygwin, ASCII English/latin letters without diacritics and Arabic decimal digits; in the C locale [[:alnum:]]
and [a-zA-Z0-9]
match the same thing).
Above using the '...'
form of quoting that is the strongest one (no character is special within them).
+
, |
, (...)
are extended regexp operator (not basic regexp operators as expected by grep
without -E
). Without -x
, grep
would look for matches within the lines, so for example would match on a line like:
foo@bar.com x.y.z@enron.common.br whatever
^^^^^^^^^^^^^
Without LC_ALL=C
, [[:alnum:]]
could match on characters of other alphetical scripts (like the Greek, Cyrillic, Korean ones), and [a-z]
could match on some latin characters with diacritics like á
, ç
, ÿ
but not others like áºÂ
, Ã
º
as they come after z
...
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
@AndresZW, add-v
to report the lines that don't match.
â Stéphane Chazelas
May 8 at 15:18
@AndresZW, see edit aboutLC_ALL=C
. I'd say it's the most minor of the problems in your original code.
â Stéphane Chazelas
May 8 at 15:20
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
 |Â
show 1 more comment
up vote
2
down vote
accepted
up vote
2
down vote
accepted
[
, ,
(
and )
all have special meanings to the shell and should be quoted if you intend to pass them verbatim in an argument to a command (here grep
).
Also note that ranges like [a-z]
make little sense outside of the C locale.
So here, you probably want:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@(E|e)nron.com' < some-file
Or:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@[Ee]nron.com' < some-file
To report the lines that match that E
xtended regular expression ex
actly. With the al
phanum
erical characters limited to those of the C
locale (so on Cygwin, ASCII English/latin letters without diacritics and Arabic decimal digits; in the C locale [[:alnum:]]
and [a-zA-Z0-9]
match the same thing).
Above using the '...'
form of quoting that is the strongest one (no character is special within them).
+
, |
, (...)
are extended regexp operator (not basic regexp operators as expected by grep
without -E
). Without -x
, grep
would look for matches within the lines, so for example would match on a line like:
foo@bar.com x.y.z@enron.common.br whatever
^^^^^^^^^^^^^
Without LC_ALL=C
, [[:alnum:]]
could match on characters of other alphetical scripts (like the Greek, Cyrillic, Korean ones), and [a-z]
could match on some latin characters with diacritics like á
, ç
, ÿ
but not others like áºÂ
, Ã
º
as they come after z
...
[
, ,
(
and )
all have special meanings to the shell and should be quoted if you intend to pass them verbatim in an argument to a command (here grep
).
Also note that ranges like [a-z]
make little sense outside of the C locale.
So here, you probably want:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@(E|e)nron.com' < some-file
Or:
LC_ALL=C grep -xE '[[:alnum:]]+.[[:alnum:]]+@[Ee]nron.com' < some-file
To report the lines that match that E
xtended regular expression ex
actly. With the al
phanum
erical characters limited to those of the C
locale (so on Cygwin, ASCII English/latin letters without diacritics and Arabic decimal digits; in the C locale [[:alnum:]]
and [a-zA-Z0-9]
match the same thing).
Above using the '...'
form of quoting that is the strongest one (no character is special within them).
+
, |
, (...)
are extended regexp operator (not basic regexp operators as expected by grep
without -E
). Without -x
, grep
would look for matches within the lines, so for example would match on a line like:
foo@bar.com x.y.z@enron.common.br whatever
^^^^^^^^^^^^^
Without LC_ALL=C
, [[:alnum:]]
could match on characters of other alphetical scripts (like the Greek, Cyrillic, Korean ones), and [a-z]
could match on some latin characters with diacritics like á
, ç
, ÿ
but not others like áºÂ
, Ã
º
as they come after z
...
edited May 8 at 15:18
answered May 8 at 14:49
Stéphane Chazelas
279k53513845
279k53513845
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
@AndresZW, add-v
to report the lines that don't match.
â Stéphane Chazelas
May 8 at 15:18
@AndresZW, see edit aboutLC_ALL=C
. I'd say it's the most minor of the problems in your original code.
â Stéphane Chazelas
May 8 at 15:20
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
 |Â
show 1 more comment
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
@AndresZW, add-v
to report the lines that don't match.
â Stéphane Chazelas
May 8 at 15:18
@AndresZW, see edit aboutLC_ALL=C
. I'd say it's the most minor of the problems in your original code.
â Stéphane Chazelas
May 8 at 15:20
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
I think the solution is the use of LC_ALL=C.
â Andres ZW
May 8 at 15:12
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
Finally, how would it be if i want every emails that are not in that format?
â Andres ZW
May 8 at 15:15
@AndresZW, add
-v
to report the lines that don't match.â Stéphane Chazelas
May 8 at 15:18
@AndresZW, add
-v
to report the lines that don't match.â Stéphane Chazelas
May 8 at 15:18
@AndresZW, see edit about
LC_ALL=C
. I'd say it's the most minor of the problems in your original code.â Stéphane Chazelas
May 8 at 15:20
@AndresZW, see edit about
LC_ALL=C
. I'd say it's the most minor of the problems in your original code.â Stéphane Chazelas
May 8 at 15:20
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
How about the use of negative lookaround: (?!pattern)
â Andres ZW
May 8 at 15:25
 |Â
show 1 more comment
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442549%2fcygwin-unexpected-token-with-grep%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
4
How are you using it? It should be single quoted to avoid shell keywords from being parsed.
â jordanm
May 8 at 13:58
it doesn't match when i single quote it
â Andres ZW
May 8 at 14:00
1
@AndresZW: Does it match when it errors? Are you using
grep -E
?â Jesse_b
May 8 at 14:08
1
Again, how are you using it? Is it in
grep -Ex that-regex somefile
, in[[ $string =~ that-regex ]]
? What version of bash?â Stéphane Chazelas
May 8 at 14:09
1
Please edit your question using the "edit" link and include the exact code you're using and what you expect it do do.
â Stéphane Chazelas
May 8 at 14:42