From owner-freebsd-questions@FreeBSD.ORG Fri Jul 15 03:23:20 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 E680C16A41C for ; Fri, 15 Jul 2005 03:23:20 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 98AB743D46 for ; Fri, 15 Jul 2005 03:23:20 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.3) id j6F3NK6v017826; Thu, 14 Jul 2005 22:23:20 -0500 (CDT) (envelope-from dan) Date: Thu, 14 Jul 2005 22:23:20 -0500 From: Dan Nelson To: hzs202@nyu.edu Message-ID: <20050715032319.GA98600@dan.emsphone.com> References: <42D7236A.6010803@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42D7236A.6010803@gmail.com> X-OS: FreeBSD 5.4-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.9i Cc: freebsd-questions@freebsd.org Subject: Re: Problem Piping iostat -c to awk! 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: Fri, 15 Jul 2005 03:23:21 -0000 In the last episode (Jul 14), Hakim Singhji said: > I am having problems with a shell script that I am writing. I am > looking to pipe the output of iostat to awk however the shell is > hanging... even at the command line it hangs. The code looks like > this: > > # iostat -c 300 2 | egrep -v '[a-zA-Z]|^$' | awk '{print $1}' > > This code hangs for me... now when I just pipe iostat through the > egreped patter it is fine. It's when it is passed to awk that I have > problems... now of course if I simplify the output to: > > # iostat | egrep -v '[a-zA-Z]|^$' | awk '{print $1}' > > it works just fine... so it has to be the awk. What is the problem? Actually grep is the culprit. It buffers its output when piped to another program for efficiency. Try adding --line-buffering, or just let awk handle your regular expression: iostat -c 300 1 | awk '!/[a-zA-Z]|^$/ {print $1}' -- Dan Nelson dnelson@allantgroup.com