user2854333
user2854333

Reputation: 640

Sed to Insert a Value after specific line

Rewriting the whole question Again.

Hi,

I have data in a file (db_config.txt) in below format

export ORACLE_HOME=/oracle_client/instantclient_19_11
export LD_LIBRARY_PATH="$ORACLE_HOME"
ORACLE_SID=TESTDB.locahost.com; export ORACLE_SID
export PATH="$ORACLE_HOME:$PATH" 
nohup sqlplus ABCSDC/Pfgrtjf#dtt@TESTDB << EOF

Now, I capture the data in a variable

 db_connection=`cat db_config.txt`

Echo is resulting in correct data.

I am trying to insert this data into another file starting 4th line.

sed  "4 i $db_connection" test1.sh

I get following error

sed: -e expression #1, char 98: unknown command: `O'

What I understand it is not able to copy $ORACLE_HOME . I tried escaping $ with /$ in the source file but that also didn't help.

Regards.

Upvotes: 0

Views: 111

Answers (1)

anubhava
anubhava

Reputation: 786091

Based on your edited question following sed should work:

sed -i.bak '4 r db_config.txt' test1.sh

On OSX sed you may use this sed command:

sed "4 i\\
$db_connection
" test1.sh

To save changes inline:

sed -i.bak "4 i\\
$db_connection
" test1.sh

Upvotes: 1

Related Questions