Ubuntu-14.04 [SOLVED]: Using sed editor to replace a string containing backslash

Ubuntu-14.04 [SOLVED]: Using sed editor to replace a string containing backslash

Home Forums Ubuntu 14.04 Ubuntu-14.04 [SOLVED]: Using sed editor to replace a string containing backslash

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #34932

    Anonymous

    QuestionQuestion

    How can i use the sed to replace string containing backslash “” is all files of specific directory.

    I tried this but wont work for me

    find /home/tds/nfb -type f -exec sed -i 's//var/www/tds///home/tds//' {} ;
    

    I want to replace “/var/www/tds/” with “/home/tds/”

    #34933

    Anonymous

    Accepted AnswerAnswer

    You can do

    find /home/tds/nfb -type f -exec sed -i 's|/var/www/tds/|/home/tds/|' {} ;
    

    where the delimiter / is replaced by |. (sed can use almost any character as a delimiter — it picks whatever character follows the s). Alternatively, you could escape all your backslashes as follows and still used :

    sed -i 's//var/www/tds///home/tds//'
    

    Source: https://stackoverflow.com/questions/47474751/using-sed-editor-to-replace-a-string-containing-backslash
    Author: HardcoreHenry
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.