user1397417
user1397417

Reputation: 738

replace string with string in a file with bash when string contains "/"

i have an executable file that is looking for kanwadict here

/usr/local/share/kakasi/kanwadict 

when it should be looking in

/home/mrhowtos/public_html/share/kakasi/kanwadict 

so i want to replace all the

"/usr/local/share/kakasi/kanwadict"

in the executable file with

"/home/mrhowtos/public_html/share/kakasi/kanwadict"

also, i dont have privileges to write where its looking, so i cant just move the file its looking for.

i found the cmd to find and replace but its delimiters are "/"

sed -i 's/old-word/new-word/g' *.txt

so its not working for me to do this, is there another command that will work to do this?

Upvotes: 1

Views: 98

Answers (2)

koola
koola

Reputation: 1734

You need to escape the / character like \/;

sed -i 's/\/usr\/local\/share\/kakasi\/kanwadict/\/home\/mrhowtos\/public_html\/share\/kakasi\/kanwadict/g' *.txt

Upvotes: 0

anubhava
anubhava

Reputation: 785276

Use alternative delimiter like # with sed:

sed -i.bak 's#old-word#new-word#g' *.txt

for your case it will be:

sed -i.bak 's#/usr/local/share/kakasi/kanwadict#/home/mrhowtos/public_html/share/kakasi/kanwadict#g' *.txt

Upvotes: 2

Related Questions