0

My oratab file has following content:

cat /etc/oratab
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
+ASM1:/u01/app/12.2.0.1/grid:N
exaiaddb:/u02/app/oracle/product/12.2.0/dbhome_2:Y
nttest:/u02/app/oracle/product/12.2.0/dbhome_3:Y

Variable 1 : $DB_NAME=nttest

Variable 2: $DB_UNI_NAME=nttest_iad92

I simply want to find $DB_NAME in above file and replace with $DB_UNI_NAME

I tried the following, but it is not updating the file

sed -i 's/${DB_NAME}/${db_uni_name}/g' oratab

4
  • Please explain why the answers you received to yesterdays Q aren't helping you . Please update your Q above to include your best attempt at solving your problem, or we'll just think you can't be bothered. Good luck. Commented Oct 26, 2018 at 20:34
  • This is replace and update the file for permanent change. I am not sure about replacing/updating the file with new variable, so i raised this question Commented Oct 26, 2018 at 20:41
  • " Please update your Q above to include your best attempt at solving your problem" ... This sort of Q gets asked every week here. try searching for [bash] [sed] use shell variables. Good luck. Commented Oct 26, 2018 at 20:47
  • 1
    sed -i 's/${DB_NAME}/${db_uni_name}/g' oratab ... Change the single-quotes to double-quote to allow variable-expansion to take place.... Single-quotes prevent variable-expansion, so your sed command is literally looking for the characters ${DB_NAME} (that is '$', '{', 'D', 'B', ....) in your file. Commented Oct 27, 2018 at 7:10

1 Answer 1

1

The command you are using has 2 mistakes:

1.) You used the variable ${db_uni_name} in sed command. Instead, you should have used DB_UNI_NAME as you declared this above. (see difference in the case)

2.) Use double-quotes(" ") instead of single-quotes (' ') in sed command. " makes sure that sed expands the variables.

So, your command would be:

sed -i "s/${DB_NAME}/${DB_UNI_NAME}/g" oratab

This should work. Let me know.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.