Escape special character

My input is:

jdbc:Oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.147.109.211)(PORT=1526))(CONNECT_DAT A=(SID= MWDBD22)))

In the search pattern, ( and ) and . and @ are special RE, and need to be escaped \( and \) and \. and \@

how can i do it by script or command

What are you actually trying to achieve? I can't work it out from what you have written.

:confused::confused::confused:

Robin
Liverpool/Blackburn
UK

To modify a stream: sed 's/[()@.]/\\&/g'

Regards,
Alister

1 Like

Thank u....it works fine

---------- Post updated at 07:17 PM ---------- Previous update was at 07:15 PM ----------

Hi Alister,
if i use

echo $value1 | sed 's/[()@.+/]/\\&/g'

it prints the value.
can u pls tell me how to store it n variable for furthur use?
Regards,
Arindam

You can do this using 'command substitution':

someVar=$(echo $value1 | sed 's/[()@.+/]/\\&/g')
1 Like

Thank u.
i need one more help.

perl -pi -e 's/$c/$d/' test.txt

suppose i save the values in c and d variables. test.txt contains $c value.
i want to replace this value with $d value.
if i use this above command,it won't change.
what's the prob?can u pls help me?

Perhaps you should use double quotes rather than single quotes. The shell won't evaluate $c or $d if they're encased in single quotes.

1 Like

Thanks.....

Hi,
if i use array, how can i replace it:

perl -pi -e "s/${d[$i]}/${b[$j]}" *.xml

if i execute, it shows
Substitution replacement not terminated at -e line 1.

Consult your previous perl command (post #6) to see how to properly terminate the substitution replacement.

Regards,
Alister