sed - Substituting text in a file within a Perl script -


I am using webmin and I am trying to change some settings in a file. I'm having trouble if that person uses any strange letter which can use either sed or perl using the following code:

  and execute_command ("sed -i 's / ^ $ Pref. * \ $ / $ Pref \ "$ $ {$ Pref} \" / g '$ DIR / pserver.prefs.cache ");  

Where execute_command is basically a webmin function for running a particular system call $ pref is the priority name such as "server", "option 2" etc. And there is going to be a option in the $ {pref} option that I want to set for the PREF. For example, here is a specific pserver.prefs :

  server name "test name" OWNERPASSWORD "Hd8sdH and 3"  

Therefore, if we call SERVERNAME to Tes "t # & amp; ^" @ '"@@ & amp; amp; and OWNERPASSWORD * @ (& amp;" @ $ " ('') 29 , they will be passed as $ in {pref} . What is the easiest way to avoid variables in the $ in {} So that they can work properly sed, or better yet, what's the way I can convert my sed command to strictly in Perl command Do not have errors in it?

Update:

Awesome, now I'm just trying to work with it and I get this error:

  ** / bin / sh: -c: Line 0: Unexpected EOF while searching for matching `` / Bin / sh: -c: Line 1: Syntax Error: Unexpected End of File **  

This does not work:

  my $ Pref = "& amp; * ()) (* & '' '^% $ # @! & Amp ;; execute_command ("perl -pi -e 's / ^ server * \ $ / Server \ "\ q $ pref \ e \" / gi '$ DI r / pserver.prefs ");  

It does this:

  My $ pref = "& amp; * ()) (* & Amp; ^% $ # @! & Amp; exec; execute_command ("PERL -pi -e 's / ^ SERVERNAME. * \ $ / SERVERNAME \" \ Q $ Pref \ E \ "/ g' $ DIR / pserver.prefs ");  
  $ i = '(* and *) * $ pounds (*'; if ($ i = ~ / \ Q) $ I \ E /) {print "matches! N ";}  

Without a \ Q and \ E, you get an error due to regex symbols in $ I .


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -