Sed substitution works independently but not a script

I have a file lets call it disablejobs.sql that has the following line:

exec dbms_Scheduler.disable(NSARRI.JOB_DATADUMP_ADMIN_11, force => TRUE);

I want to put a tick around NSARRI.JOB_DATADUMP_ADMIN_11 so that the line can look like this:

exec dbms_Scheduler.disable('NSARRI.JOB_DATADUMP_ADMIN_11', force => TRUE);

If I use the following it works just fine:

sed -i 's/disable(/disable('\''/g' disablejobs.sql
sed -i 's/, force/'\'', force/g' disablejobs.sql

BUT, when I use the same sed command in a shell script it complains

+ su - oracle -c 'sed -i '\''s/disable\(\/disable\('\''/g\ disablejobs.sql'
sed: -e expression #1, char 40: unterminated `s' command

@nsarri , welcome, please, code/data to be in triple backticks - use the menu options to do this (i've done it this time for you !)

possible solution below enlosed in double quotes with multiple substitutions separated by semi-colon (read the sed man page for details etc) , - (there'll be others)

NB:I don't have oracle so haven't tried using an intermediate process

cat disablejobs.sql

exec dbms_Scheduler.disable('NSARRI.JOB_DATADUMP_ADMIN_11', force => TRUE);

sed -i "s/disable(/disable\('/g ; s/, force/', force/g" disablejobs.sql

cat disablejobs.sql 
exec dbms_Scheduler.disable('NSARRI.JOB_DATADUMP_ADMIN_11', force => TRUE);

MunkeHoller,
Thanks for responding. I can do that myself running the sed from the command line. That's not the problem. The issue comes when I use this in a shell script.

I am having a hard time putting a tick where I need to put. But if I want to put dot or any other character? that works. But not a tick, as it thinks that a tick needs to have a closing tick.

Solved. Here it how this works in a shell script:

su - oracle -c 'sed -i "s/disable(/disable('\''/g; s/, force/'\'', force/g" disablejobs.sql'

Thanks again MunkeHoller.

You say "shell script" but you mean "su shell".

The problem is, you need another level of quoting. You found the best solution, the " " quotes for the second level.

The alternative is ugly.
You correctly had: to quote a ' within ' ' it must be '\''
Now the next level: to quote a '\'' within ' ' it would be '\''\'\'''\''
Prove:

bash -c 'echo '\''A '\''\'\'''\''ticked'\''\'\'''\'' word.'\'''
A 'ticked' word.
1 Like