Subject: Re: Using sed to update bind zone file serial

> for i in *; do grep "serial number" | cat "$i"|sed -e
> 's/??????????/2006082200 ; serial number./' >>"$i".new; done
> The grep statement gets the entire serial # line and I was simply
> going to replace that line with the new line including the update
> serial number. Unfortunately I cannot figure out what to use as my
> first statement in the sed command.

the output of the grep command is *only* the line containing
"serial number". You likely want to have other lines in your
output file. Thus, you likely want something like

sed -i.bak '/serial number/s/[0-9][0-9]*/2006072200/' *

which would replace your whole shebang.

To decode that:

sed run sed
-i change the files in place,
.bak saving a backup to {original name}.bak
/serial number/ on lines matching this text
s/foo/bar/ change things matching "foo" to "bar"
* for all the files in the directory
(which is what you passed to your "for" loop)

In this instance, "foo" is


which translates to "any digit in the range 0-9 followed by zero
or more (the asterisk) digits in the range 0-9"

"bar" is boringly your replacement timestamp.

If you don't want to modify the originals in place, you can use

for i in *; do
sed '/serial number/s/[0-9][0-9]*/2006072200/' "$i" > "$"

(presuming it's okay to tromp on top of $

This assumes files have lines that look something like

serial number 123456778


serial number 987654321


123462346897 serial number

where "serial number" and the number are the only things of
consequence on the...


With some example input data, one might be able to make a smarter
regexp, but this dumb one should do for now.

Also note that "serial number" has one and only one space in it.
If this isn't always the case, you can change it in the sed
statement to something like


I'm afraid I've not got any sample Bind files on hand to check
this against. So as always, caveat seditor. YMMV and stuff. :)



Yahoo! Groups Links

<*> To visit your group on the web, go to:

<*> To unsubscribe from this group, send an email to:
[email protected]

<*> Your use of Yahoo! Groups is subject to:

Programming list archiving by: Enterprise Git Hosting