I try to search and replace a given string in a Makefile, that is
PROCFLAGS="SQLCHECK=SEMANTICS USERID=$(CONNECT)"
Where I want to add CODE=ANSI_C to the line
PROCFLAGS="SQLCHECK=SEMANTICS USERID=$(CONNECT) CODE=ANSI_C"
Sed should do this trick very good.. at least that's what I thought but I can't get behind what syntax error I am doing calling sed:
sed -i'.bak' s:(CONNECT):(CONNECT) CODE=ANSI_C:g Makefile
I have tried to add -r or escape the brackets \( \) but I always end up with the error:
-bash: syntax error near unexpected token `('
I can only think of something I must be doing wrong here as many other replacements really work fine.
Try quoting the bracketed items. Bash is attempting to run (CONNECT) in a sub shell I think
sed -i'.bak' "s:(CONNECT):(CONNECT) CODE=ANSI_C:g" Makefile
When you put something in brackets, bash will run it as a command in a subshell.
For example, try (cd /tmp; pwd); pwd. You will see the subshell print /tmp, but then the second pwd will tell you the original directory.
Put your sed code inside quotes.
sed -i'.bak' 's:(CONNECT):(CONNECT) CODE=ANSI_C:g' Makefile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With