help with updating date+revision in a file

Hi Gurus,

I have a file in which the 3rd line needs to be replaced with 'current date' along with 'revision'. The exact format of the file is like this:

$TTL 4h
@ IN SOA mo2idns.mnc720.mcc302.gprs. root.mnc720.mcc302.gprs. (
                                2011020801; serial YYYYMMDDVV where VV is version
                                5h ; slaves should refresh the zone after 5 hours
                                2h ; retry after 2 hour
                                30d ; expire after 30 days
                                10m ) ; negative cache TTL of 10 minutes

The file extract above shows that the file was last updated on 8th of Feburary and it was only changed once because I see a '01' appended to the date. (If there was a '02' instead of '01', that would mean the file was updated twice on the 8th of Feburary)

Is that possible in shell scripting to update the date in the 3rd line with current date along with revision. So if the file has previous date, the date will be replaced with today's date along with first revision: 2011020901 ('01' because it is first revision / update for today). And if the date is detected to be today's date then just add 1 to the revision say from 2011020901 to 2011020902 , or from 2011020902 to 2011020903, depends on how many times the file has already been revised / updated today.

Any help will be appreciated.

Thanks
momin

today=$(date +%Y%m%d)

awk -v t=$today '
NR==3{  d=substr($1,1,8);i=substr($1,9,2);
        $1=(t==d)?d i+1 ";" :t "01;"
     }1' infile > tmp
mv tmp infile

This is what I am getting:

# awk -v t=$today 'NR==3 { d=substr($1,1,8);i=substr($1,9,2); $1=(t==d)?d i+1 ";" :t "01;" }1' db.gprs > tmp
bash: tmp: cannot overwrite existing file
#

Can you pointg out where I an going wrong?

I guess there is a file or folder named tmp already, created by different user.

You have no permission to overwrite it. So just change to other name.