How to remove a few DNS records from all zone files?

postcd

Well-Known Member
Oct 22, 2010
717
19
68
Hello,

WHM stupidly without asking me added all Default nameservers into zone files of accounts i transfered to my server.

The aim is now fix the mess WHM did.

Removing whole entry lines

nsx1.hosting.com X X X IP
nsx2.hosting.com X X X IP

there is more than 100 zone files to edit. so i ask how i can remove these two whole lines automatically via linux command line from all zone files.
 

cPanelPeter

Technical Analyst III
Staff member
Sep 23, 2013
575
21
143
cPanel Access Level
Root Administrator
Twitter
Hello,

You could use the replace command. First if you haven't already done so, make a backup of the /var/named directory

Code:
cp -rfpd /var/named /var/named.bak
Then you would use the replace command something like this:

Code:
replace 'nsx1.hosting.com X X X IP' '' -- *
replace 'nsx2.hosting.com X X X IP' '' -- *
That should do the trick. If anything goes wrong, you still have the backup.