Re: suggested addition to 'date'



On 2006-08-11 20:19, Sam Leffler <sam@xxxxxxxxx> wrote:
Julian Elischer wrote:
At various times I've wanted to add timestamps to logfiles as they are
generated..

usually this has involved perl or something to do it.

pbj% ls | sed -e "s/^/`date +'%+: '`/"
Fri Aug 11 20:18:05 PDT 2006: Desktop
Fri Aug 11 20:18:05 PDT 2006: Desktop DB
Fri Aug 11 20:18:05 PDT 2006: Desktop DF
Fri Aug 11 20:18:05 PDT 2006: Documents
Fri Aug 11 20:18:05 PDT 2006: Library
Fri Aug 11 20:18:05 PDT 2006: Movies
...

Unfortunately this won't work. The `backquoted` command is expanded
only once -- before the rest of the command-line runs:

$ for sec in 1 2 3 4 5 ; do echo "second $sec" ; sleep 1; done | sed -e "s/^/`date +'%+: '`/"
Sat Aug 12 06:38:03 EEST 2006: second 1
Sat Aug 12 06:38:03 EEST 2006: second 2
Sat Aug 12 06:38:03 EEST 2006: second 3
Sat Aug 12 06:38:03 EEST 2006: second 4
Sat Aug 12 06:38:03 EEST 2006: second 5
$

Using Perl and ``Time::HiRes qw(gettimeofday)'' is the best trick I've
found so far for this sort of thing :-/

_______________________________________________
freebsd-current@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@xxxxxxxxxxx"