grep: Syntax error near unexpected token `('

11,602

sounds like you're not using proper simple quote ('). Try to copy and paste this one:

grep -E '( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} '

(I have the same error in bash if I copy and paste your script, which use instead of ')

Share:
11,602

Related videos on Youtube

fergiu
Author by

fergiu

Updated on September 18, 2022

Comments

  • fergiu
    fergiu over 1 year

    I have this problem: I'm looking for a string inside file . Syntax is:

    grep -E ‘( ^ |  [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ’  (filename) 

    When I run this command inside ubuntu I get this error:

    Syntax error near unexpected token `('

    Why?

    • Manuel Faux
      Manuel Faux about 9 years
      For me the command works. Which shell do you use?
    • Арсений Черенков
      Арсений Черенков about 9 years
      it look like a copy/paste from a word-like document, quotes, double quotes are often turn to a fancier quote, but no longer work in linux.
    • fergiu
      fergiu about 9 years
      grep -E ‘( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ’ (filename) run correctly: it was a stupid character question. But now I have an error grep: memory exhausted when I try to run this statement inside a dd file (very big file). Do You have some indications about this ?
  • fergiu
    fergiu about 9 years
    Thanks: it run correctly BUT I have a new problem. I have a dd file that is very big. When I run this statement I have an error: grep: memory exhausted. Have You some indications for this problem ?
  • apaul
    apaul about 9 years
    Hi, dd is for Disk Dumps, thus contains binary data. It's unlikely you have to grep such a file... If you really want to, you may try to find only characters strings in that file then grep them: strings file.dd | grep ... If your file is actually only text, you may split it in several smaller files, for instance: split -n 500000 file.dd (man split) then grep the generated files (which are by default aa, ab, ac, ...)