Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Oct 2015 06:03:51 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Quartz <quartz@sneakertech.com>
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>

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



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