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 '
)
Related videos on Youtube
Author by
fergiu
Updated on September 18, 2022Comments
-
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 about 9 yearsFor me the command works. Which shell do you use?
-
Арсений Черенков about 9 yearsit 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 about 9 yearsgrep -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 about 9 yearsThanks: 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 about 9 yearsHi,
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 defaultaa
,ab
,ac
, ...)