Good afternoon monks,
I have a very large .txt file containing approximately 800,000 lines of text. Each line, at some point, contains at least two timestamps which are currently in Unix time. Below are examples of two lines from my data:
Misc data that is unimportant:false,true,false,"retrieved_on":14335074 +59,more misc data,nul;,true,"created_utc":"1433122764", "retrieved_on":1433507472,misc data,"created_utc":"1433122764",true,fa +lse,more misc data
I am trying to convert all of the Unix timestamps to a more traditional date and time format using the following code:
use strict; use utf8; open(FILE, '<C:/Users/li/perl/part1.txt') || die "File not found"; my @lines = <FILE>; close(FILE); my @newlines; foreach(@lines) { $_ =~ s/([\d]{10})/localtime $1/eg; push(@newlines,$_); } open(FILE, '>C:/Users/li/perl/part1_CORRECTED.txt') || die "File not f +ound"; print FILE @newlines; close(FILE);
However, while this code does, technically work, it returns the date and time in a strange format which is not helpful to when my analysing my data further:
Misc data that is unimportant:false,true,false,"retrieved_on":Fri Jun + 5 13:30:59 2015,more misc data,nul;,true,"created_utc":"Mon Jun 1 0 +2:39:24 2015", "retrieved_on":Fri Jun 5 13:31:12 2015,misc data,"created_utc":"Mon J +un 1 02:39:24 2015",true,false,more misc data
Is there a way that I can modify my code to return the output in a more intuitive style (e.g. maybe YYYY:MM:DD HH:MM:SS or similar)?
Thank you in advance!
In reply to Converting multiple unix timestamps by Maire
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |