[Techtalk] bash scripting with sed

Hamster hamster at hamsternet.org
Fri Nov 22 22:59:06 EST 2002


Neefer,

I assume you are referring to the first instance of $NAME.

The reason is because bash does not expand vars inside single quotes '

Replace with " and the var will get substituted.

Hamster

> 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
> 



More information about the Techtalk mailing list