13 ts adds a timestamp to the beginning of each line of input.
15 The optional format parameter controls how the timestamp is formatted,
16 as used by L<strftime(3)>. The default format is "%b %d %H:%M:%S".
18 If the -r switch is passed, it instead converts existing timestamps in
19 the input to relative times, such as "15m5s ago". Many common timestamp
20 formats are supported. Note that the Time::Duration and Date::Parse perl
21 modules are required for this mode to work.
25 The standard TZ environment variable controls what time zone dates
26 are assumed to be in, if a timezone is not specified as part of the date.
30 Copyright 2006 by Joey Hess <joey@kitenet.net>
32 Licensed under the GNU GPL.
38 use POSIX
q{strftime};
44 GetOptions
("r" => \
$rel) || die "usage: ts [-r] [format]\n";
54 my $format="%b %d %H:%M:%S";
55 $format=shift if @ARGV;
59 print strftime
($format, localtime)." ".$_;
63 \d\d
[-\s\
/]\w\w\w
# 21 dec 17:05
64 (?
:\
/\d\d+)? # 21 dec/93 17:05
65 [\s
:]\d\d
:\d\d
# (time part of above)
66 (?
::\d\d
)?
# (optional seconds)
67 (?
:\s
+[+-]\d\d\d\d
)?
# (optional timezone)
69 \w
{3}\s
+\d\d\s
+\d\d
:\d\d
:\d\d
# syslog form
71 \d\d\d
[-:]\d\d
[-:]\d\dT\d\d
:\d\d
:\d\d
.\d
+ # ISO-8601
73 (?
:\w\w\w
,?\s
+)?
# (optional Day)
74 \d
+\s
+\w\w\w\s
+\d\d
+\s
+\d\d
:\d\d
:\d\d
76 (?
:\s
+\w\w\w
|\s
+-\d\d\d\d
)?
79 \w\w\w\s
+\w\w\w\s
+\d\d\s
+\d\d
:\d\d
83 concise
(ago
(time - str2time
($1), 2))