Hello everyone, I am using the following Perl one liner in a ksh script to process a file of dates and change them to a different format and attach a counter of 1 to each date processed. I must have something wrong, when I have entries like:
1300483666
which is Fri Mar 18 17:27:46 2011 for which I would expect an output of the form:
2011 03 18 05 21 1
this code returns:
2011 03 18 05 17 1
This is the code I use :
perl -lne '($j1,$j2,$hour,$mday,$mon,$year,$wday) = gmtime($_);$year = + $year + 1900;$mon++;printf("%4s %.2d %.2d %.2d %.2d %6s\n",$year,$mo +n,$mday,$wday,$hour,1);' < inputFile >outputFile
I really hope someone can help and explain my error. Thanks!

In reply to Perl date conversion by gio001

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.