2

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?

5
  • 1
    For me the command works. Which shell do you use? Commented Apr 7, 2015 at 13:08
  • 1
    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
    Commented Apr 7, 2015 at 13:59
  • Be careful with the spaces inside regexps...
    – JJoao
    Commented 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
    Commented Apr 8, 2015 at 7:28
  • Either the shell, or whatever you're copy-and-paste'ing from, are mangling your quotes or whitespace. Try typing the command afresh, rather than copy-and-paste. If you're running it from inside a (shell-)script, then whichever shell that's running could be mangling the command; turn on verbosity and execute shell-options to see what's literally getting onto the command line.
    – smci
    Commented Feb 20 at 3:08

1 Answer 1

6

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

2
  • 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
    Commented 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
    Commented Apr 8, 2015 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .