On 2006-08-11 20:19, Sam Leffler <sam_at_errno.com> 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 :-/Received on Sat Aug 12 2006 - 01:41:18 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:58 UTC