Search and replace a line in perl

Hi All,
i can replace a perticular value in sentence using perl.
perl -pi -e 's/old/new/' sample.txt
but i am not able to replace whole string by perl.

file1 contains "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.147.109.211)(PORT=1526))(CONNECT_DATA=(SID= MWDBD22)))". i want to change this value with following target value.

target value:"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(FAILOVER=yes)(LOAD_BALANCE=yes)(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.223.236)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.223.237)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=RICPCF.shareprod.org)))"

i used the following one. bt it didn't change the value

perl -pi -e "s/jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.147.109.211)(PORT=1526))(CONNECT_DATA=(SID= MWDBD22)))/jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(FAILOVER=yes)(LOAD_BALANCE=yes)(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.223.236)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=10.144.223.237)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=RICPCF.shareprod.org)))/" file1

I am afraid you need to \ escape each special character:
In the search pattern, ( and ) and . are special in perl RE, and need to be escaped \( and \) and \.
In both the search pattern and the substitution string the @ needs to be \@ escaped because it is always special in Perl.

1 Like

Thank u.
now i can replace by using \ for each special character.

Hi,
Can i place those escape characters by script automatically? i mean to say that when it gets one special character,place '/' before this in automatic way.