TransWikia.com

Sed command writes the expression in outer ifmodule

Unix & Linux Asked by Ariana williams on January 9, 2021

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/

One Answer

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

Answered by Kusalananda on January 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP