Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jul 2005 22:23:20 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        hzs202@nyu.edu
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Problem Piping iostat -c to awk!
Message-ID:  <20050715032319.GA98600@dan.emsphone.com>
In-Reply-To: <42D7236A.6010803@gmail.com>
References:  <42D7236A.6010803@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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