Search replace strings between single quotes

Hi All,

I need to serach and replace a strings between single quote in a file.
My file has :
location='/data1/test.log' and the output needed is
location='/data2/test_dir/test.log'

pls if anybody know this can be done in script sed or awk.

I have a script, but it's error :

sed -i "s/'[^']*'/`echo /data2/test_dir/test.log`/g" file_name

any help would be appreciated!!

Thanks
mnmonu

sed -i 's:'\''[^'\'']*'\'':'\''/data2/test_dir/test.log'\'':' file

If that doesn't work, you may use "the orbiting laser gun" for sparking a camp fire (someone on this forum quoted this humourous line :-P)

perl -pe 's:\047.*?\047:\047/data2/test_dir/test.log\047:' file

Hi balajesuri,

It's ok but when we put the environment variable that time error.

sed -i 's:'\''[^'\'']*'\'':'\''$ORACLE_HOME/test.log'\'':' file

suppose $ORACLE_HOME is /u01/app/oracle/product/10.2.0/db_1 , then output should be

location='/u01/app/oracle/product/10.2.0/db_1/test.log'

perl -pe 's:\047.*?\047:\047/'$ORACLE_HOME'/test.log\047:' file

Thanks balajesur,
But I can't use perl in our environment. Is there any shell script?

sed -i "s:'/data1/test.log':'$ORACLE_HOME/test.log':" file
1 Like

Thanks balajesuri, it's working