-2
sed -i 's/'$search'/'$replace'/g' $file

this command is able to replace only strings..but i wanted to search and replace any kind of strings in a file

Ex : if i give input

 $search= /jms/CodeBasev1.23*
 $replace= /jms/CodeBasev1.24/baseline*.

it should search for exact string and replace the exact line .. Not only with slashes but also it should accept meta-characters also

ex: [..],%,&,() ..etc

Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133

1 Answers1

0
perl -0777 -pi -e's/\Q$ENV{search}/$ENV{replace}/g' $file

-0777 is only necessary if the search string contains literal newlines.

ysth
  • 96,171
  • 6
  • 121
  • 214