timestamping a text stream

Simon Barner barner at in.tum.de
Mon May 19 04:30:22 PDT 2003


Hi,

> Does anybody know of a program similar to script(1) or tee(1) that will
> timestamp each line of input as it happens?

You can use this perl script:

#!/usr/bin/perl -w
# This is timestamp.pl

use strict;

my $line=undef;
my $stamp;
while (defined ($line = <>)) {
	$stamp = localtime (time ());
	print ("$stamp: $line");
}

echo "foo" | ./timestamp.pl
Mon May 19 13:25:31 2003: foo

> Ultimately, I want each line of a `make buildworld` timestamped.

So, something like 'make buildworld 2>&1 | ./timestamp.pl' is what you
want.

Simon


More information about the freebsd-questions mailing list