From owner-freebsd-questions@FreeBSD.ORG Wed Nov 9 18:43:53 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D767616A420 for ; Wed, 9 Nov 2005 18:43:53 +0000 (GMT) (envelope-from bsilverstrim@athensasd.org) Received: from mail.athensasd.k12.pa.us (rrcs-24-97-187-226.nys.biz.rr.com [24.97.187.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3AE6F43D45 for ; Wed, 9 Nov 2005 18:43:53 +0000 (GMT) (envelope-from bsilverstrim@athensasd.org) Received: from [172.16.0.190] ([172.16.0.190]) by mail.athensasd.k12.pa.us with Microsoft SMTPSVC(5.0.2195.6713); Wed, 9 Nov 2005 13:43:52 -0500 In-Reply-To: <20051109180353.GA10584@flame.pc> References: <06fe145ebc265841b4c499f5dc1e72ab@athensasd.org> <20051109180353.GA10584@flame.pc> Mime-Version: 1.0 (Apple Message framework v623) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Bart Silverstrim Date: Wed, 9 Nov 2005 13:44:44 -0500 To: Giorgos Keramidas X-Mailer: Apple Mail (2.623) X-OriginalArrivalTime: 09 Nov 2005 18:43:52.0347 (UTC) FILETIME=[87D416B0:01C5E55D] Cc: freebsd-questions@freebsd.org Subject: Re: log file conversion (OT?) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2005 18:43:54 -0000 On Nov 9, 2005, at 1:03 PM, Giorgos Keramidas wrote: > On 2005-11-09 12:36, Bart Silverstrim > wrote: >> I have Squid running on a FreeBSD system and the log file (access.log) >> has lines like >> >> 1131556815.537 101 172.16.2.153 TCP_HIT/200 35674 GET >> http://www.urprize2.com/adv77/images/header_08_23_05.gif - NONE/- >> image/gif >> 1131556815.584 47 172.16.2.153 TCP_HIT/200 1828 GET >> http://www.urprize2.com/adv77/images/timer.swf - NONE/- >> application/x-shockwave-flash >> >> in it. Is there a simple way or a one- or two-liner script >> that can take the epoch time in the first column and replace it >> with the actual time/date stamp in human-readable format? > > Yes. Perl should work fine here. > > $ echo '1131556815.537 101 172.16.2.153 TCP_HIT/200 35674 GET' > | \ > perl -MPOSIX=strftime \ > -pe 'chomp; @x=split /\./; \ > $ts = strftime "%Y-%m-%d %H:%M:%S", (localtime($x[0])); \ > $_=$ts.".".join(".",@x[1,$#x])."\n";' > 2005-11-09 09:20:15.537 101 172.153 TCP_HIT/200 35674 GET Is there a way to get it to take in each line of the logfile and output it to a new file? It wouldn't be as easy as a "cat access.log | (perl code here) >> newfile.log" would it?