0

I try to replace some text in a file with the command sed from bash

I want to replace the line :

$app["gentle.root"] = "/home/doc/";

to

$app["gentle.root"] = "/home/exemple/";

I try :

sed -i's/$app["gentle.root"] = "/home/doc/";/$app["gentle.root"] = "/home/exemple/";' /home/martialp/Documents/default.php

But I'm getting this error

sed: -e expression n°1, caractère 7: commande inconnue: `m'

2 Answers 2

1

You should escape spcial symbols:

sed -i 's/\$app\[\"gentle.root\"\] = \"\/home\/doc\/\"\;/\$app\[\"gentle.root\"] = \"\/home\/exemple\/\"\;/'  /home/martialp/Documents/default.php
Sign up to request clarification or add additional context in comments.

1 Comment

or you can avoid having to escape N number of / chars, by using an alternate substitute/replace field delimiter, like s@1/string@2/string' Some seds require being "notified" that you're deliberatly using an alternate delim, and you have to do s\@1/string@2/string@' Good luck to all.
0

Think from another way, and recommend to use other Character if the replace line has "/" in it.

sed '/gentle.root/ s#/home/doc#/home/exemple#' file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.