moreutils (0.31) UNRELEASED; urgency=low
* pee.1: Document difference with tee in stdout.
+ * ts: Support displaying fractional seconds via a "%.S" conversion
+ specification. Closes: #482789
-- Joey Hess <joeyh@debian.org> Wed, 28 May 2008 13:42:01 -0400
ts adds a timestamp to the beginning of each line of input.
The optional format parameter controls how the timestamp is formatted,
-as used by L<strftime(3)>. The default format is "%b %d %H:%M:%S".
+as used by L<strftime(3)>. The default format is "%b %d %H:%M:%S". In
+addition to the regular strftime conversion specifications, "%.S" is
+expanded to fractional seconds (ie, "30.00001").
If the -r switch is passed, it instead converts existing timestamps in
the input to relative times, such as "15m5s ago". Many common timestamp
formats are supported. Note that the Time::Duration and Date::Parse perl
modules are required for this mode to work.
-If both -r and a format is passed, the format existing timestamps are
+If both -r and a format is passed, the existing timestamps are
converted to the specified format.
=head1 ENVIRONMENT
my $format="%b %d %H:%M:%S";
$format=shift if @ARGV;
+# For fractional seconds, Time::HiRes is needed.
+my $hires=0;
+if ($format=~/\%\.S/) {
+ require Time::HiRes;
+ $hires=1;
+}
+
while (<>) {
if (! $rel) {
- print strftime($format, localtime)." ".$_;
+ if ($hires) {
+ my $f=$format;
+ my ($seconds, $microseconds) = Time::HiRes::gettimeofday();
+ my $s=sprintf("%06i", $microseconds);
+ $f=~s/\%\.S/%S.$s/g;
+ print strftime($f, localtime($seconds));
+ }
+ else {
+ print strftime($format, localtime);
+ }
+ print " ".$_;
}
else {
s{\b(