2

I'm trying to change the path in a oracle sql script from a bash script.

read -e -p "Enter the ORACLE SID: " -i "orcl" ORACLE_SID_VALUE
sed -i "DEFINE tsdir = '/u02/app/oracle/oradata/orcl';/c\DEFINE tsdir = '/u02/app/oracle/oradata/${ORACLE_SID_VALUE}'" schema-install.sql

when I execute the script i get the following error: sed: -e expression #1, char 2: extra characters after command

can anyone please help me with the correct sed command.


more info

just to clarify: in the file schema-install.sql, there is a line defining where the oracle database will stored.

DEFINE tsdir = '/u02/app/oracle/oradata/orcl';

I want to change the value orcl to the value I type into the variable ORACLE_SID_VALUE.

  • what is this supposed to do?: DEFINE tsdir = ? – mikeserv Sep 10 '14 at 9:54
  • It will define the directory where the Oracle database will be placed – Lars Grotell Sep 10 '14 at 10:18
  • Ok, but that's nonsense to sed. It does understand a D command, but no DEFINE and so on will be parsed will be parsed correctly. If that's to be part of a regex you've got to format it correctly. – mikeserv Sep 10 '14 at 10:20
  • The line in the sql script is: DEFINE tsdir = '/u02/app/oracle/oradata/orcl'; – Lars Grotell Sep 10 '14 at 10:21
  • That is the line you desire to change? And you wish to append the $ORACLE_SID_VALUE to the end of the path as Archemar has already shown? – mikeserv Sep 10 '14 at 10:22
1

I would try:

sed -i -e "/DEFINE tsdir = /c\
DEFINE tsdir = '/u02/app/oracle/oradata/${ORACLE_SID_VALUE}'
" schema-install.sql

sed is confused by / in path definition.

  • The error was that the line in the sql file had an TAB, that i did not see. It works now. thanks. – Lars Grotell Sep 10 '14 at 12:04
0

From what I understand from your question you are trying to replace

DEFINE tsdir = '/u02/app/oracle/oradata/orcl'

by

DEFINE tsdir = '/u02/app/oracle/oradata/${ORACLE_SID_VALUE}'

If this is what you are trying to do , You can achieve this using

sed -i "s#DEFINE tsdir = '/u02/app/oracle/oradata/orcl'#DEFINE tsdir = '/u02/app/oracle/oradata/${ORACLE_SID_VALUE}'#" schema-install.sql
  • sorry it does not work – Lars Grotell Sep 10 '14 at 11:10
  • it is working for me. Can you paste how you ran it and your output. – g4ur4v Sep 10 '14 at 11:53
  • The error was that the line in the sql file had an TAB, that i did not see. It works now. thanks. – Lars Grotell Sep 10 '14 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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