How do I update the dates (by 30 days) in the files going to that specific location in unix? Can awk or sed help ?

File format is as below -

Thomson: xyz
Format: 1
Character_set: ASCII8
File_type: event_file
File_subtype: mobile_call
File_group_number: 1
File_in_group_number: 1
Total_files_in_group: 19
Source_ID: source
Tag: tag -v13

This file produced by GTFplaintext 0.1:

Event: "61765","1","2014/01/03-13-00-00.00",,"GBP",,,,,,,,,,"61765","0345351816","1407",,,,,,,,,,,,,,,,,,,,,
Footer: text_data_transfer_file
AuditValue_1: 1
AuditValue_2: 0
End: text_data_transfer_file
Lines: 15
Characters: 351

In the above file I need to go to the line starting with 'Event:' and update the date
"2014/01/03-13-00-00.00" by 30 days (only date needs to be updated, while time can remain same).
There are 20k such files in a directory, for which the dates have to be updated.

  • 1
    Note that some date and time combinations are invalid: TZ=America/Sao_Paulo date -d '2012-10-21T00:00'
    – choroba
    Mar 11, 2015 at 12:09

2 Answers 2


With perl and the Date::Manip module, you could do:

 perl -MDate::Manip -pi -e 's|^Event.*?"\K\d{4}/\d\d/\d\d|
   UnixDate(DateCalc("$&", "30 days later"), "%Y/%m/%d")|e' file1 file2...
awk '
    "date +\"%Y/%m/%d\" -d \""d" 30 days\""|getline ds
  1' file

For lines which starts from Event: find substring matching date format and put in in variable d. Then use system date command to set variable ds as date more than d for 30 days and substitute d by ds in string.

  • but the problem is there are mutiple lines starting with Event and each line has different date, if let's assume the below event has date as 2014/01/03, other Event (next line) may have date as 2014/01/08 and next event may have different date. All such Events in the file need to be moved ahead by 30 days -Event: "61765","1","2014/01/03-13-00-00.00",,"GBP",,,,,,,,,,"61765","0345351816","1407",,,,,,,,,,,,,,,,,,,,, Mar 13, 2015 at 6:28
  • @Unix_Novice And what is the question? Something do not work?
    – Costas
    Mar 13, 2015 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .