1
    I have a requirement to replace all the lines in a file that start with a certain string to be replaced by a variable.

Contents of te file -

    SDI=/u05/rdbms/admin
    NONSDI=/u07/rdbms/admin1
    NONNON=/u01/rdbms/
    SDI=/u05/rdbms/admin3

I have a variable SDI_N="SDI=/u01/data/admin/instance"

$echo $SDI_N
SDI=/u01/data/admin/instance

Expected output -

  $cat file
     SDI=/u01/data/admin/instance
     NONSDI=/u07/rdbms/admin1
     NONNON=/u01/rdbms/
     SDI=/u01/data/admin/instance

I am trying the following -

sed -e "s/^SDI=.*/${SDI_N}/g" file
ERROR - sed: -e expression #1, char 16: unknown option to `s'

sed -i 's/^SDI=.*/\${SDI_N}/' file

It does not replace with the value of SDI_N

       $cat file 
       ${SDI_N}
       NONSDI=/u07/rdbms/admin1
       NONNON=/u01/rdbms/
       ${SDI_N}

Nor is this helping

sed -i 's/^SDI=.*/"${SDI_N}"/' file

sed -e "s/^SDI=.*/${SDI_N}/g"  file
       sed: -e expression #1, char 16: unknown option to `s'

Please let me know what changes I will have to make to my existing code to get the desired output.The issue could be with " or '. But I am unable to get through. I used all the possible combination of Single and Double quotes but with no success.

0 Answers0