text - bash sed substitution in httpd.conf -
i trying replace line of text in file using sed , bash. here code. think syntaxs may off.
sed -e 's/documentroot /var/www/html/s///usr/share/rt3/html/' /etc/httpd/conf/httpd.conf
when using sed , file paths, it's easier avoid "/" delimiter, else you'll escaping everytime. "picket fence" format makes terrible read.
assuming you're trying replace "documentroot /var/www/html" "documentroot /usr/share/rt3/html/", try this:
sed 's_documentroot /var/www/html_documentroot /usr/share/rt3/html/_' /etc/httpd/conf/httpd.conf
example:
~> echo "documentroot /var/www/html" | sed 's_documentroot /var/www/html_documentroot /usr/share/rt3/html/_' documentroot /usr/share/rt3/html/ ~>
edit: comment, you're wanting 1) open file, 2) replace string, , 3) save changes original file. in case, can use sed's -i
flag (in-place editing). try this:
sed -i 's_documentroot /var/www/html_documentroot /usr/share/rt3/html/_' /etc/httpd/conf/httpd.conf
example:
~> echo "documentroot /var/www/html" > file ~> cat file documentroot /var/www/html ~> sed -i 's_documentroot /var/www/html_documentroot /usr/share/rt3/html/_' file ~> cat file documentroot /usr/share/rt3/html/
Comments
Post a Comment