#!/usr/bin/perl print "This program reads epoch seconds from stdin and converts them, ctrl-d to end/cancel\n"; while (<>) { if ($_ =~ m/(\d\d\d\d\d\d\d\d\d\d)/){ $epoch=$1; chomp($epoch); $_ =~ s/$epoch//; print "(", scalar localtime $epoch, ") $_"; } else { print $_; } }
1198878644 some really usefull log entry that you would love to know when it happened
(Fri Dec 28 13:50:44 2007) some really usefull log entry that you would love to know when it happened
#!/usr/bin/env python3 import re import sys import time print("This program reads epoch seconds from stdin and converts them, ctrl-d to end/cancel") epoch_pattern = '(\d\d\d\d\d\d\d\d\d\d)' for line in sys.stdin: epoch_str = re.search(epoch_pattern, line) if epoch_str: epoch = int(epoch_str.group()) timestamp = time.strftime("%a %b %d %H:%M:%S %Y", time.localtime(epoch)) print(line.replace(epoch_str.group(), timestamp)) else: print(line)