0

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/"

Q8root
  • 1,243
  • 3
  • 25
  • 48
  • 1
    Are you trying to replace a backslash `\ ` or a forward slash `/`? Your text says one but your example the other. – Ed Morton Nov 24 '17 at 16:14

1 Answers1

2

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\//'
HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44