1

my config file has this

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

I want to change index.php to index.temp

I created this

sed -i -e '/s/index.php/index.temp/‘ dir.conf

It makes this,

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
ndex.php/index.temp/
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • 4
    You presumably want to use the `s` substitute command, so do not begin with `/` as `/s/` means match the pattern `s`, and then the command is `i` which inserts the rest of the line. So use `sed -i -e 's/index.php/index.temp/'` – meuh Nov 03 '18 at 20:06

1 Answers1

0

Your s/// command is prefixed by a / which would make sed misunderstand it. It also looks as if the terminating single quote is not an ordinary single quote ( instead of '), but that may be an issue in just this question.

To change all instances of the string index.php to index.temp in some file dir.conf, use

sed -i 's/index\.php/index.temp/g' dir.conf

The dot in the pattern needs to be escaped as it is special in regular expressions (you could also have used [.] in place of \.). Also note that this is using -i for "in-place editing", which is not generally portable.

To make sure that you don't change myindex.php into myindex.temp or index.php3 into index.temp3, use \< and \> (or \b in place of both) to match the word boundaries:

sed -i 's/\<index\.php\>/index.temp/g' dir.conf
Kusalananda
  • 320,670
  • 36
  • 633
  • 936