Cygwin unexpected token `(' with grep

The name of the pictureThe name of the pictureThe name of the pictureClash 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







share|improve this question

















  • 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















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







share|improve this question

















  • 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













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







share|improve this question













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









share|improve this question












share|improve this question




share|improve this question








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 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













  • 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








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











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 Extended regular expression exactly. With the alphanumerical 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...






share|improve this answer























  • 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 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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 Extended regular expression exactly. With the alphanumerical 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...






share|improve this answer























  • 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 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














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 Extended regular expression exactly. With the alphanumerical 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...






share|improve this answer























  • 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 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












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 Extended regular expression exactly. With the alphanumerical 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...






share|improve this answer















[, , ( 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 Extended regular expression exactly. With the alphanumerical 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...







share|improve this answer















share|improve this answer



share|improve this answer








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 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
















  • 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 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















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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay