From owner-freebsd-questions@FreeBSD.ORG Wed Aug 27 06:52:24 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DCCE51065680 for ; Wed, 27 Aug 2008 06:52:24 +0000 (UTC) (envelope-from paul+fbsd@it.ca) Received: from mail.it.ca (mail.it.ca [216.235.7.67]) by mx1.freebsd.org (Postfix) with ESMTP id 6A9538FC23 for ; Wed, 27 Aug 2008 06:52:24 +0000 (UTC) (envelope-from paul+fbsd@it.ca) Received: from mail.it.ca (paul@mail [216.235.7.67]) by mail.it.ca (8.13.3/8.13.3) with ESMTP id m7R6qNb1034069; Wed, 27 Aug 2008 02:52:23 -0400 (EDT) (envelope-from paul+fbsd@it.ca) DomainKey-Signature: a=rsa-sha1; s=a; d=it.ca; c=nofws; q=dns; h=received:x-authentication-warning:date:from:to:cc:subject: message-id:reply-to:references:mime-version:content-type: content-disposition:in-reply-to:user-agent; b=uthE/GLwW/Wfm199nSQfjocc8KVErUdZ0vg6i2skZDUUyH4xMWWvQTUyKeXkgxVuz DIKJAZR2mRQdUYq/WuQCOAH7YaWcqlpbhCFsLfKfj7CRyTWr2PdE9Qby0CnukPV Received: (from paul@localhost) by mail.it.ca (8.13.3/8.13.3/Submit) id m7R6qNEm034066; Wed, 27 Aug 2008 02:52:23 -0400 (EDT) (envelope-from paul+fbsd@it.ca) X-Authentication-Warning: mail.it.ca: paul set sender to paul+fbsd@it.ca using -f Date: Wed, 27 Aug 2008 02:52:22 -0400 From: Paul Chvostek To: DAve Message-ID: <20080827065222.GA30783@it.ca> References: <48AECD11.1000705@pixelhammer.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48AECD11.1000705@pixelhammer.com> User-Agent: Mutt/1.5.12-2006-07-14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (mail.it.ca [216.235.7.67]); Wed, 27 Aug 2008 02:52:23 -0400 (EDT) Cc: 'User Questions' Subject: Re: Tailing logs X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Aug 2008 06:52:24 -0000 On Fri, Aug 22, 2008 at 10:28:33AM -0400, DAve wrote: > > I would love to have a way to tail a log, like piping to grep, except I > see every line and the lines I would normally grep for are highlighted. > That would be cool. Anyone know of a bash command or tool that will do this? I use tcsh as my shell. The following alias works nicely for me in xterm, but would have to be adjusted for anything else: alias highlight 'sed -E '\''s/\!:*/^[[1m&^[[0m/g'\''' Replace "^[" with an escape character, twice. Put it in your .tcshrc if you like. YMMV. > Side note, I am tailing sendmail after changes to my outbound queue > runners. I want to highlight my sm-mta-out lines but still see all lines. Right, I do very similar stuff. You'd use this like: tail -F /var/log/maillog | highlight .*sm-mta-out.* Quotes seem to confound this alias. I haven't bothered to fix that; as long as what you're searching for doesn't glob a file, you should be fine without quotes. You can also do more complex things in either sed or awk, colour-coding individual pattern matches. Here's one in awk that I use to highlight the activity of milter-greylist: #!/usr/bin/awk -f BEGIN { red="^[[31m"; green="^[[32m"; yellow="^[[33m"; blue="^[[34m"; norm="^[[0m"; fmt="%s%s%s\n"; } /autowhitelisted/ { printf(fmt, green, $0, norm); next; } /delayed for/ { printf(fmt, yellow, $0, norm); next; } # /skipping greylist/ { printf(fmt, blue, $0, norm); next; } { print; } Same deal with the "^[". Enjoy. p -- Paul Chvostek it.canada http://www.it.ca/