Created
October 2, 2012 19:02
-
-
Save danslimmon/3822522 to your computer and use it in GitHub Desktop.
add_timestamps.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# What it does (example): | |
# | |
# dan@cleon:~/tools/server$ yes | ./add_timestamps.pl | head | |
# 2012-10-02 14:59:16.579109 y | |
# 2012-10-02 14:59:16.579180 y | |
# 2012-10-02 14:59:16.579210 y | |
# 2012-10-02 14:59:16.579240 y | |
# 2012-10-02 14:59:16.579269 y | |
# 2012-10-02 14:59:16.579299 y | |
# 2012-10-02 14:59:16.579329 y | |
# 2012-10-02 14:59:16.579370 y | |
# 2012-10-02 14:59:16.579390 y | |
# 2012-10-02 14:59:16.579420 y | |
use Time::localtime; | |
use Time::Local; | |
use Time::HiRes; | |
while (my $line = <>) { | |
my $time = Time::HiRes::clock_gettime(CLOCK_REALTIME) . "\n"; | |
my $time_ipart = int $time; | |
my $time_fpart = $time - $time_ipart; | |
my $loctime = localtime($time_ipart); | |
my $time_str = sprintf("%04d-%02d-%02d %02d:%02d:%02d.%06d", | |
$loctime->year + 1900, | |
$loctime->mon + 1, | |
$loctime->mday, | |
$loctime->hour, | |
$loctime->min, | |
$loctime->sec, | |
int($time_fpart*1e6)); | |
print "$time_str $line"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment