From owner-freebsd-questions@freebsd.org Mon Oct 5 04:03:54 2015 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A1B01A10DC8 for ; Mon, 5 Oct 2015 04:03:54 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 688551BE5 for ; Mon, 5 Oct 2015 04:03:53 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de (port-92-195-13-98.dynamic.qsc.de [92.195.13.98]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 86E9A3CC4F; Mon, 5 Oct 2015 06:03:51 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id t9543pXP007259; Mon, 5 Oct 2015 06:03:51 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Mon, 5 Oct 2015 06:03:51 +0200 From: Polytropon To: Quartz Cc: freebsd-questions@freebsd.org Subject: Re: awk question Message-Id: <20151005060351.3646d1b7.freebsd@edvax.de> In-Reply-To: <5611EEE2.9030100@sneakertech.com> References: <5611C922.4050007@hiwaay.net> <5611EEE2.9030100@sneakertech.com> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Oct 2015 04:03:54 -0000 On Sun, 04 Oct 2015 23:30:42 -0400, Quartz wrote: > Considering you're referring to 'pulling out lines', maybe you want to > trap the output of smartctl into a variable, then just echo that to grep > a bunch of times, before awk? > > ie; > > x=$(smartctl) > > echo "$x" | grep 'foo' | awk '{print $1}' > echo "$x" | grep 'bar' | awk '{print $2}' > echo "$x" | grep 'baz' | awk '{print $3}' > > ...etc? Note that awk has "builtin grep", so your example could be combined to one smartctl call: smartctl | awk ' /foo/ { print $1; } /bar/ { print $2; } /baz/ { print $3; } ' Of course storing the smartctl output to a variable is very useful when processing it _multiple_ times. But as you said, awk is quite versatile. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...