Perl Gods,
I am generating a CSV file with the first 2 columns in the Epoch time format. I want to be able to run a script that converts and replaces these fields with a human readable date. How would I got about doing that - I'm just learning Perl so if you could explain it to me like I'm 5 that'd be great haha!
CSV:
1345752662, 1345752673, CLOSED, CRITICAL, Other fields etc
What I want:
I'm in the GMT-5 timezone and am not sure how to do that part either. Thanks in advance!Thu Aug 23 2012 15:11:02, Thu Aug 23 2012 15:11:13, CLOSED, CRITICAL, +ETC
***************UPDATE:*****************
Here is the solution I came up with thanks to you guys!
#!/usr/bin/perl use strict; use Text::CSV; use Tie::File; my (@records, @removed); tie @records, 'Tie::File', "test.csv"; @removed = splice(@records,0,2); print join ("\n", @records); untie @records; my $file = 'test.csv'; my $csv = Text::CSV->new(); open (CSV, "<", $file) or die $!; open (MYFILE, '>>convertedDate.csv'); #Column Headers #First 2 are in Epoch time print MYFILE "Arrival, Modified Date, Severity, Status, TicketID, Mess +age\n"; close (MYFILE); while (<CSV>) { if ($csv->parse($_)) { open (MYFILE, '>>convertedDate.csv'); my @columns = $csv->fields(); #I know this next line isn't so elegant print MYFILE scalar(localtime(@columns[0])) . "," . scalar(local +time(@columns[1])) . ",\"" . @columns[2] . "\",\"" . @columns[3] . "\ +",\"" . @columns[4] . "\",\"" . @columns[5] . "\""; print MYFILE "\n"; close (MYFILE); } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV;
In reply to Epoch time conversion in CSV by theneil
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |