Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Feb 1999 21:29:18 +1000
From:      Greg Black <gjb@comkey.com.au>
To:        Dan Busarow <dan@dpcsys.com>
Cc:        Hugh Blandford <hugh@island.net.au>, questions@FreeBSD.ORG
Subject:   Re: Changing large no. of DNS records 
Message-ID:  <19990223112918.20129.qmail@alpha.comkey.com.au>
In-Reply-To: <Pine.BSF.3.96.990222103438.6495G-100000@java.dpcsys.com>  of Mon, 22 Feb 1999 10:38:37 PST
References:  <Pine.BSF.3.96.990222103438.6495G-100000@java.dpcsys.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > I'm changing IP addresses of a nameserver :((  I also need to change the MX
> > records in all my zone files.  Is there a utility that I can make look in
> > each file in a directory and do the equivalent of a global search and replace.
> 
> sed
> 
> # cd /etc/namedb
> # for i in db.*
> # do
> # sed -f sedfile $i > $i.out
> # mv $i $i.save
> # mv $i.out $i
> # done
> 
> # cat sedfile
> s/IN MX 10 mail.my.domain./IN MX 10 newmail.my.domain./g

The basic concept is okay, but sed is definitely the wrong tool
here.  Since he wants to edit files in place, the correct tool
is ed -- that way you avoid all the silly creation of the .out
files and the subsequent renaming:

    for f in db.* ; do ed -s $f < edfile ; done

And edfile is something like this:

    /MX 10 mail.my.domain/s//MX 10 newmail.my.domain/
    wq

Of course, for both the sed and ed solutions, the actual REs
that you use will probably have to be a little more complex,
since it's not at all likely that you could rely on the files
being so consistent as these trivial examples show.  But that's
just an exercise.

-- 
Greg Black <gjb@acm.org>



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990223112918.20129.qmail>