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.


In reply to Convert Epoch times in Logfile by stevbutt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.