LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-19-2011, 06:43 PM   #1
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Rep: Reputation: 1
using sed to change zone file serial number


Hi Guys...

I have just started to learn about 'sed' and find it very useful.

I wonder if it is possible to change the serial number in DNS zone files enblock.

eg. Change: 2010121901()or whatever the number is) To: 2011121901

In perl there is a command:
Code:
perl -i -p -e 's/\d\d\d\d\d\d\d\d\d\d/2011121901/' *
This will run through all the zone files in the directory and change them all.

Has anybody any ideas ???

John C
 
Old 12-19-2011, 06:59 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
The perl command could be shortened to:
Code:
perl -i -pe 's/\d{10}/2011121901/' *
A similar sed line:
Code:
sed -i -e 's/[0-9]\{10\}/2011121901/' *
edit:
Both commands search for 10 digits numbers, maybe you could restrict the research more

Last edited by Cedrik; 12-19-2011 at 07:02 PM.
 
1 members found this post helpful.
Old 12-19-2011, 07:13 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
sed or not, I find that approach somewhat risque ... while it
doesn't make too much sense there's still nothing to stop a user
from defining hostnames that consist of 10 digits - I don't
think you'd want ALL of those to be equal to your new serial?


That said:
Code:
sed -r -e '/^[\t ]+[0-9]{10}[\t ]*;[\t ]*serial/ s/[0-9]{10}/2011121901/' *
I made the word "serial" a necessary condition for the replacement,
just for sanitys sake. And of course bear in mind that if you change
the file for the 2nd time on the same day the tailing two digits need
to be incremented ... thought I'd chuck that in for good measure. ;}



Cheers,
Tink


P.S.: Beat too it :} ... that's what happens if you start responding
and walk away. =o)
 
Old 12-19-2011, 07:13 PM   #4
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Original Poster
Rep: Reputation: 1
Hi Cedrik..

Thank you so much for your extremely quick reply.

I have tested both these commands and found that they work fine for me.
This is going to save me a lot of time when I transfer all my domains to a new server.

THANK YOU.

John C
 
Old 12-19-2011, 07:22 PM   #5
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Original Poster
Rep: Reputation: 1
Hi Tinkster...
Quote:
Btw, I'll rather attempt to aid you in helping yourself than
giving you a "turn-key solution". I believe in enabling people
to help themselves, rather than carrying them everywhere. ;}
I have been looking for around 4 hous for an answer to my question.
I tried man pages and google and didn't get anywhere near an answer.
That was when I decided to put a post on the forum.
I can only spend so much time looking and getting nowhere
 
Old 12-19-2011, 07:41 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by countrydj View Post
Hi Tinkster...

I have been looking for around 4 hous for an answer to my question.
I tried man pages and google and didn't get anywhere near an answer.
That was when I decided to put a post on the forum.
I can only spend so much time looking and getting nowhere

Whether or not you chose to take my SIGNATURE personally is
entirely up to you my friend ... =o)


Cheers,
Tink
 
Old 12-22-2011, 06:09 AM   #7
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,452

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
Now, if it were me, I would as a matter of principle always write such code to read one file as input and to write another copy of that file as output ... then to do some renaming so that when the program finished it had the "new" copy in-place and one or more "backup" copies nearby.

Code:
set_my_speed( miles_per_hour(100) );
shoot(foot);

Last edited by sundialsvcs; 12-22-2011 at 06:11 AM.
 
  


Reply

Tags
perl, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script to change TTL of all zone file search4u2003 Linux - Server 2 07-13-2011 11:09 AM
Sed/awk/grep search for number string of variable length in text file Alexr Linux - Newbie 10 01-19-2010 02:34 PM
why block number changed after change of file? bitzsk Linux - Kernel 2 06-05-2009 08:10 AM
Using SED to change a file incomingid Linux - Newbie 4 04-17-2009 01:47 PM
Dns Problem Loading The Zone File Error(zone File Not Found) ramineni Linux - Newbie 1 09-14-2008 09:36 AM


All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration