By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,660 Members | 1,299 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,660 IT Pros & Developers. It's quick & easy.

Please Help for perl Script

P: 1
HI Guru,
I am newbabe in perl, Could you please help me out.
I am having a file withComma (,) seprater data records. Like below 2 lines
01/09/2008 00:00:00,+99001000000001,http://wap.mysite.com/news/world/ind...00-Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)

01/09/2008 00:00:02,+99002000000002,http://wap.mysite.com/news/business/....xx,LGE-CX5450 UP.Browser/6.2.2.3.d.1.103 (GUI) MMP/2.0

--------------------------------------
I would like to replace first filed of the line date (01/09/2008) with adding 5 month in existing date and rest of the data should be same.using perl scripts

Input File:
01/09/2008 00:00:00,+99001000000001,http://wap.mysite.com/news/world/ind...00-Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)

Result file I need:
01/02/2009 00:00:00,+99001000000001,http://wap.mysite.com/news/world/ind...00-Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)


Note: date in Input file: 01/09/2008 changed to 01/02/2009 means that scripts should add 5 month into exsiting date in file.

Looking for your response asap.

Thanks
Max
Mar 24 '09 #1
Share this Question
Share on Google+
2 Replies


gpraghuram
Expert 100+
P: 1,275
To add 5 months to a date you can make use of time functions.
You can first get the tick count for the date in the input.
Add 30 * 5* 86400
then convert the tick back to normal date.

I think there is a date calculator also in unix , which i have used some time back(but i dont remember the command name)

Raghu
Mar 27 '09 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
@maxman1

To do this, you are going to have to disect each line and pull out the date, then use something like the date::calc module from cpan in order to do the modification.

Why not give this a try and then post your code here if you get stuck.

Regards,

Jeff
Mar 27 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.