[Techtalk] bash scripting with sed
J Neefer!
neefer at speakeasy.org
Fri Nov 22 12:28:35 EST 2002
Hi,
I'm trying to write a bash script to do several things on some
dns zone files:
(1) rename the files
(2) modify the TTL, etc numbers from seconds to the 1H, etc format
(3) change the name server and contact in the SOA
(4) add some commented-out entries to the body of the file
I've got everything except #4 working. What I want to do is
insert a bash $VAR into the sed command, but sed is barfing up an
error on it.
The script looks like this (the ^T characters are literal tabs in
the script file):
for FILE in `ls pri.*`
do
NAME=`echo $FILE | cut -d. -f2,3`
NAME="$NAME.hosts"
sed -e '
s/SOA ns.mydomain.net/SOA ns1.mydomain.com/;
s/admin.ns.mydomain.net/hostmaster.mydomain.com/;
s/10800/8H/;
s/3600/1H/;
s/604800/1W/;
s/^Tin^T/^TIN^T/;
s/^Ta^T/^TA^T/;
s/^Tcname^T/^TCNAME^T/;
s/^;$//;
/^www.*/a
;www.$NAME\. IN A 2.2.2.2
' $FILE > $NAME
done
That append is inserting the literal '$NAME' when I want the
contents of the bash variable to be inserted instead.
So how do I get the *value* of $NAME into my sed command?
Thanks.
--Neefer
More information about the Techtalk
mailing list