0

I want to search and replace specific value in a file, here is the content of the file

filename: /etc/httpd/conf/httpd.conf
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

I want to replace DocumentRoot /var/www/html with DocumentRoot /var/www/html/centos

I tried the following

sudo sed -i "s#DocumentRoot /var/www/html#DocumentRoot /var/www/html/centos#g" /etc/httpd/conf/httpd.conf

This is not working, can someone point me to the right direction.

Thanks

2 Answers 2

1

The line you are trying to replace is:

DocumentRoot "/var/www/html"

It contains double-quotes. The sed command does not include the double-quotes. Try:

sudo sed -i 's#DocumentRoot "/var/www/html"#DocumentRoot "/var/www/html/centos"#g' /etc/httpd/conf/httpd.conf
Sign up to request clarification or add additional context in comments.

Comments

0

Nevermind, i figured it out, i was missing double quotes, following command worked

sudo sed -i 's#DocumentRoot "/var/www/html"#DocumentRoot "/var/www/html/centos"#g' /etc/httpd/conf/httpd.conf

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.