Question : Using sed to remove lines from a config file

I have a script I am trying to run that will remove lines from an apache configuration file for a particular domain.  The lines are added via another script and it works fine and is added in the exact format I am trying to remove.  I must have the sed expression screwed up or something because it just prints the whole config file again without removing the lines I want.

The script is executed like so:
./script.sh domain.com aliasdomain.com

Here is the script:


#!/bin/sh

DOMAIN=$1;
ALIASDOMAIN=$2;


FQDOMAIN="www.$DOMAIN"
etc_conf_file=/tmp/httpd.include

echo -e "Removing http/web forwarding for $DOMAIN\n\n";

# Setup the /etc conf file
echo -e "Clearing the /etc config file.\n";
etc_conf="\n\tServerName   $DOMAIN\n\tServerAlias  $FQDOMAIN\n\tRedirect Permanent / \"http://www.$ALIASDOMAIN/\"\nualHost>\n"
echo -e $etc_conf;

sed -e s_"$etc_conf"_""_g $etc_conf_file > $etc_conf_file.tmp




Any help would be much appreciated.

Answer : Using sed to remove lines from a config file

nognew:
I tried your solution however that didn't seem to work either.  I guess my problem is trying to edit multiple lines with a line editor.  I ended up solving it by finding the starting and ending line numbers and then deleting them with sed like so:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
DOMAIN=$1;
ALIASDOMAIN=$2;
 
 
FQDOMAIN="www.$DOMAIN"
etc_conf_file=/etc/apache2/httpd.include
 
echo -e "Removing http/web forwarding for $DOMAIN\n";
 
startline=`grep -n -B 2 -A 2 $DOMAIN $etc_conf_file | cut -s -d "-" -f1 | head -n1`;
endline=`grep -n -B 2 -A 2 $DOMAIN $etc_conf_file | cut -s -d "-" -f1 | tail -n1`;
 
sed -i -e "$startline,$endline d" $etc_conf_file
Open in New Window Select All
Random Solutions  
 
programming4us programming4us