From owner-freebsd-questions@freebsd.org Mon Oct 5 03:30:51 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 3DCE6A100E9 for ; Mon, 5 Oct 2015 03:30:51 +0000 (UTC) (envelope-from quartz@sneakertech.com) Received: from douhisi.pair.com (douhisi.pair.com [209.68.5.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 201C11815 for ; Mon, 5 Oct 2015 03:30:50 +0000 (UTC) (envelope-from quartz@sneakertech.com) Received: from [10.2.2.1] (pool-108-49-223-195.bstnma.fios.verizon.net [108.49.223.195]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by douhisi.pair.com (Postfix) with ESMTPSA id DE4FE3F71B for ; Sun, 4 Oct 2015 23:30:42 -0400 (EDT) Message-ID: <5611EEE2.9030100@sneakertech.com> Date: Sun, 04 Oct 2015 23:30:42 -0400 From: Quartz MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: awk question References: <5611C922.4050007@hiwaay.net> In-Reply-To: <5611C922.4050007@hiwaay.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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 03:30:51 -0000 On Oct 4 8:48 PM, William A. Mahaffey III wrote: > > > I am using awk & smartctl in a small shell script to print out HDD temps > in a purty format, 1 line per drive. As it happens, the output I want is > spread out over 4 lines of smartctl out, requiring (I *think*) 4 calls > to smartctl each piped to its own awk invocation to pull out the line I > want & print its info out. Is there some way to get awk to consider more > than 1 line at a time ? In my case my 4 lines are indeed sequential, & > it would be a bit more efficient if I could process all 4 lines once I > found the 1st one. This is definitely *not* critical, what I have now > works AOK, I was/am just curious if it could be optimized a bit. TIA & > have a good one. Awk already handles multiple lines just fine, so you're looking for something else but don't know how to articulate it. 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? Although depending on what exactly you want to pull from the smartctl output, you can probably just do it all from awk in one incantation. Awk scripts can be fairly powerful.