stevbutt has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have a log file which has the following format ( its nominally CSV )
John@gmail.com,1268727836,lots,more,fields
I would like to change the second field to a date format the DB I am going to load this into will understand rather than Epoch time i.e.
John@gmail.com,2010/03/16 08:23:56,lots,more,fields
and if possible also add a field at the end of the line containing the original file name i.e.
John@gmail.com,2010/03/16 08:23:56,lots,more,fields,logfile1.log
Whats an efficient way to do this in perl ( there are lots of files with millions of lines ) ? I have found I can generate an individual date which would work with the following code
perl -MPOSIX -le 'print strftime "%F %T", localtime 1268727836'
Its just the looping through the file and running this to sub field 2 in every line that I cant seem to crack - Any help greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert Epoch times in Logfile
by NetWallah (Canon) on Jun 08, 2012 at 00:22 UTC | |
by stevbutt (Novice) on Jun 08, 2012 at 01:07 UTC | |
by jwkrahn (Abbot) on Jun 08, 2012 at 01:10 UTC | |
|
Re: Convert Epoch times in Logfile
by locked_user sundialsvc4 (Abbot) on Jun 08, 2012 at 14:32 UTC |