2

I am trying to search and replace the text of a single line with sed characters inside that line. The line is a file path thus it has /*. instead of it. I have searched and found n\ and opposing \ but non of these seem to work. Whatever I am doing wrong it's simple, but I can't see the tree through the forest.

data to edit:

Include conf.d/*.conf

I am trying to edit the

conf.d/*.conf 
conf.d/vhosts/*.conf

Include is else where in the file, but this is the only occurrence where it's the first word. this is what I have so far:

sed -i "/^Include/ s/\conf.d/*.conf\/ */\conf.d/vhosts/*.conf\/" /etc/httpd/conf/httpd.conf

I've alsow tried

sed -i "/^Include/ s/[conf.d/*.conf]/[conf.d/vhosts/*.conf]/g" /etc/httpd/conf/httpd.conf

This is the standard search error message:

Error Message: sed: -e expression #1, char 29: unknown option to `s'

I know it's something simple, but I can't seem to figure it out. I have been stuck on this for the past hour. If I can get past this, then I can edit the documentroot and other elements with sed like characters.

sed version GNU sed version 4.2.1

David
  • 891
  • 1
  • 8
  • 18
  • possible duplicate of [sed: -e expression #1, char 23: unknown option to \`s'](http://stackoverflow.com/questions/22182050/sed-e-expression-1-char-23-unknown-option-to-s) – tripleee Apr 15 '14 at 16:18
  • @tripleee Thanks for pointing this out. However, I'm trying to make this a single line if possible. My goal is to edit the httpd.conf file at Include conf.d/*.conf and replace the conf.d with a users input. I wasn't able to find what I was looking for via search, so I posted the question. I'm newish, and still learning how this community works. – David Apr 15 '14 at 18:00

1 Answers1

1
sed -i "s|conf.d/\*.conf|conf.d/vhosts/\*.conf|g" /path/to/file
  • Changed Separator to |
  • Escaped asterisk
Curtis Mattoon
  • 4,642
  • 2
  • 27
  • 34
  • this works wonderfully and it's simple, I can use the old pathname and a new pathname example: sed -i "/^Include/ s|$oldpathname\*$oldextention|$newpathname\*.$newextention|g" httpd.test I can also use this for document root and a few hundred other application. It's simple and it works. Thank you. – David Apr 15 '14 at 14:30