Visit The New, Modern Unix Linux Community


help with updating date+revision in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with updating date+revision in a file
# 1  
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:
HTML Code:
$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

Last edited by momin; 02-09-2011 at 06:11 PM..
# 2  
Code:
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

# 3  
This is what I am getting:
HTML Code:
# 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?
# 4  
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.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #407
Difficulty: Medium
Cygwin's default package selection is quite small, containing little more than the bash shell and the core file manipulation utilities expected of a Unix command line.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Updating in file

hi, i have an csv(which is a month's log file containing userid and log in date ) file which has to be appended to another file say master.log.I need to compare the next month's log data to master.log file .In case, there is new log date for userid it has to get updated in master.log file or i... (2 Replies)
Discussion started by: preema
2 Replies

2. UNIX for Dummies Questions & Answers

Updating a File

Hi, I have a below requirement and need your help in this regard. I have two timestamps in a file i.e. TimeBefore=2014-07-10.18.06.55 TimeAfter_1=2014-07-09.05.45.12 TimeAfter_2=2014-07-09.05.40.12 When I first run the script file, it sets the 'TimeBefore' to todays date. When I run... (5 Replies)
Discussion started by: vrupatel
5 Replies

3. Shell Programming and Scripting

Help updating a file

I can not seem to figure out how to update the attached match.txt column 2 using update.txt. However, only the text before the period in updat.txt appears in match.txt. For example, in update.txt NM_001613.2 matches NM_001613 in match.txt, so is it possible to update the record in match.txt to... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

bash script to find date based on search string for continuesly updating file

Hi All, I am very new to UNIX and I have tried this for a longtime now and unable to crack it.... There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day..... eg: String is "work started" The log entry is as below: ... (1 Reply)
Discussion started by: Nithz
1 Replies

5. Shell Programming and Scripting

Reading from one file and updating other file with constant entries

Hi All, Thaks for the help in my last thread. I have one more question. I have two files with ldap entries in it. One file contains all the user LDAP parameter entries (26 MB) and other file contains only the user id's that have to be inactivated. Unix script has to read from the file that has... (8 Replies)
Discussion started by: Samingla
8 Replies

6. Shell Programming and Scripting

AWK and sub/gsub: updating a date/time block

I have a file ("modtest") in which I want to update the last date/time block in the lines beginning with a period. Here is a sample: .ROMULT 10150908EDT 10270908EDT 10010908EDT RANGE RAWV2 1.00 .ROMULT 10150908EDT 10270908EDT 10010908EDT FGROUP CHOWANRV 1.00 .RRIMULT 10150908EDT... (10 Replies)
Discussion started by: chrismcg24
10 Replies

7. UNIX for Dummies Questions & Answers

Updating a field in a File without creating temp file's

Hi Experts, I have a requirement where i need to update the below items in file, 1. END TIME 2. PREV_STATUS For the first time the PREV_status and end time of all job the job will be sysdate & NULL reply as below, Session_name,Load Type,Frequency,Seesion End time,Prev_Status... (2 Replies)
Discussion started by: prabhutkl
2 Replies

8. UNIX for Advanced & Expert Users

wtmpx file is not updating

Hi in my solaris 9 system wmptx file is not updating so it is not recording any login or logout or any other entry. can any one tell me how to solve this problem (0 Replies)
Discussion started by: aaysa123
0 Replies

9. Shell Programming and Scripting

awk updating one file with another, comparing, updating

Hello, I read and search through this wonderful forum and tried different approaches but it seems I lack some knowledge and neurones ^^ Here is what I'm trying to achieve : file1: test filea 3495; test fileb 4578; test filec 7689; test filey 9978; test filez 12300; file2: test filea... (11 Replies)
Discussion started by: mecano
11 Replies

10. Shell Programming and Scripting

TO know whether file is updating or not

Hi All, I am new to scripting. my requirement is , I want to know whether the file(i.e., log file) is updating or not. It should search for every 15 min. If it is not updating means it needs to send out a automatic mail. can you please help me in this. (2 Replies)
Discussion started by: raj333
2 Replies

Featured Tech Videos