Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Aug 2006 06:40:08 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Sam Leffler <sam@errno.com>
Cc:        Julian Elischer <julian@elischer.org>, current@freebsd.org
Subject:   Re: suggested addition to 'date'
Message-ID:  <20060812034008.GC80768@gothmog.pc>
In-Reply-To: <44DD48C8.7000805@errno.com>
References:  <44DD4510.5070002@elischer.org> <44DD48C8.7000805@errno.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-08-11 20:19, Sam Leffler <sam@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 :-/




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060812034008.GC80768>