From owner-freebsd-current@FreeBSD.ORG Sat Aug 12 03:41:18 2006 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 715EE16A4E1 for ; Sat, 12 Aug 2006 03:41:18 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id A7FC443D49 for ; Sat, 12 Aug 2006 03:41:14 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.pc (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.7/8.13.7/Debian-2) with ESMTP id k7C3e8vM007709 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 12 Aug 2006 06:40:12 +0300 Received: from gothmog.pc (gothmog [127.0.0.1]) by gothmog.pc (8.13.7/8.13.7) with ESMTP id k7C3e8p4081705; Sat, 12 Aug 2006 06:40:08 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.pc (8.13.7/8.13.7/Submit) id k7C3e8ec081704; Sat, 12 Aug 2006 06:40:08 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Sat, 12 Aug 2006 06:40:08 +0300 From: Giorgos Keramidas To: Sam Leffler Message-ID: <20060812034008.GC80768@gothmog.pc> References: <44DD4510.5070002@elischer.org> <44DD48C8.7000805@errno.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44DD48C8.7000805@errno.com> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-3.813, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.59, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: Julian Elischer , current@freebsd.org Subject: Re: suggested addition to 'date' X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Aug 2006 03:41:18 -0000 On 2006-08-11 20:19, Sam Leffler 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 :-/