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 `('


  • For me the command works. Which shell do you use? Apr 7, 2015 at 13:08
  • 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.
    – Archemar
    Apr 7, 2015 at 13:59
  • Be careful with the spaces inside regexps...
    – JJoao
    Apr 7, 2015 at 17:31
  • 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
    Apr 8, 2015 at 7:28

1 Answer 1


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

  • 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 ?
    – fergiu
    Apr 8, 2015 at 7:23
  • 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, ...)
    – apaul
    Apr 8, 2015 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.