Saturday, 15 January 2011

bash - Replacing a string using sed which has many different characters -


I want a variable service to be replaced by string $ service I used sed for

sed "/ SERVICE / $ service / g"

The problem is that the special characters in the variable $ service such as '$ [,], /, \,', and Similar is the sequence of special characters in the $. Service and whenever a particular character is "within the service", but fails to change it correctly is there a solution in which The remaining characters will not interfere in the sed replacement process? The answers given below do not work for me, it is called

  sed: -e expression # 1, for character 107: `s' Unknown option    

Try doing this:

  Sed @ s @ SERVICE @ $ (printf '% q' $ Service ") @ g"   
  • @ is an alternative modifier, which Any letter can be
  • Avoid the string given for printf '% Q' shell:

    Ex .

      $ printf '% q' '* $!' \ * \ $ \!    

No comments:

Post a Comment