Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Oct 2015 23:21:41 -0453.75
From:      "William A. Mahaffey III" <wam@hiwaay.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: awk question
Message-ID:  <5611F98B.5060300@hiwaay.net>
In-Reply-To: <5611EEE2.9030100@sneakertech.com>
References:  <5611C922.4050007@hiwaay.net> <5611EEE2.9030100@sneakertech.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 10/04/15 22:36, Quartz wrote:
> 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.


I missed that 1st point somehow (relatively new to using awk :-/ ), so 
that is indeed all I need to know how to do. Polytropon provided exactly 
the guidance I need (I *think*) & I will try that out on the morrow. 
Thanks & have a good one :-) ....


-- 

	William A. Mahaffey III

  ----------------------------------------------------------------------

	"The M1 Garand is without doubt the finest implement of war
	 ever devised by man."
                            -- Gen. George S. Patton Jr.




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