From owner-freebsd-questions Tue Feb 23 3:31:43 1999 Delivered-To: freebsd-questions@freebsd.org Received: from alpha.comkey.com.au (alpha.comkey.com.au [203.9.152.215]) by hub.freebsd.org (Postfix) with SMTP id 2B47F10EBC for ; Tue, 23 Feb 1999 03:31:35 -0800 (PST) (envelope-from gjb@comkey.com.au) Received: (qmail 20130 invoked by uid 1001); 23 Feb 1999 11:29:18 -0000 Message-ID: <19990223112918.20129.qmail@alpha.comkey.com.au> X-Posted-By: GBA-Post 1.04 06-Feb-1999 X-PGP-Fingerprint: 5A91 6942 8CEA 9DAB B95B C249 1CE1 493B 2B5A CE30 Date: Tue, 23 Feb 1999 21:29:18 +1000 From: Greg Black To: Dan Busarow Cc: Hugh Blandford , questions@FreeBSD.ORG Subject: Re: Changing large no. of DNS records References: In-reply-to: of Mon, 22 Feb 1999 10:38:37 PST Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message