D
David Karr
I have a pattern in an input file that looks like this:
latestTime="1379353492000"
I need to replace this with something like this:
latestTime="2013-09-16 10:34:33"
This pattern will occur in multiple lines in a file, and multiple times on a single line.
The hardest part of this seems to be to pass the milliseconds value into "strftime" as the replacement portion of the substitution regexp, for each occurrence. I can't get this to work.
This is what I have so far, and I hope I don't have to use that very strange syntax to call a function in the string (I found some references with examples like this):
#! /bin/perl
use English;
use strict;
use POSIX qw( strftime );
$| = 1;
while (my $line = <STDIN>) {
if ($line =~ /(^.*latestTime=")([0-9]+)(".*$)/) {
"\n";
$line =~ s/latestTime="([0-9]+)"/latestTime="${\strftime("%Y-%m-%d %H:%M:%S", localtime($1/1000))}"/g';
}
print $line;
}
latestTime="1379353492000"
I need to replace this with something like this:
latestTime="2013-09-16 10:34:33"
This pattern will occur in multiple lines in a file, and multiple times on a single line.
The hardest part of this seems to be to pass the milliseconds value into "strftime" as the replacement portion of the substitution regexp, for each occurrence. I can't get this to work.
This is what I have so far, and I hope I don't have to use that very strange syntax to call a function in the string (I found some references with examples like this):
#! /bin/perl
use English;
use strict;
use POSIX qw( strftime );
$| = 1;
while (my $line = <STDIN>) {
if ($line =~ /(^.*latestTime=")([0-9]+)(".*$)/) {
"\n";
$line =~ s/latestTime="([0-9]+)"/latestTime="${\strftime("%Y-%m-%d %H:%M:%S", localtime($1/1000))}"/g';
}
print $line;
}