NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Dunce awk question




On Sep 25, 2015, at 6:41 AM, William A. Mahaffey III wrote:



I am trying to use awk & grep to fashion a command to print out HDD temps, along w/ some identifying info:

I've been doing something similar, except with sed
#!/bin/mksh -p
mbmon -c 1 | sed -n '2{
h
s/, .*$//
p
}
'

atactl wd0d smart status | sed -n '/^194/{
h
s/^194.*Temperature[ ]*/wd0d =/
p
}
#tempget
Temp.= 31.0
wd0d =  28
The first grabs only line 2, and deletes everything after the first comma.
The second grabs the line the begins with 194...

If I wanted do that with awk.
#atactl wd0d smart status| awk '/^194/{print ($8) } '
33
or
#atactl wd0d smart status| awk '/^194/{print ($7, "wd0d", $8) } '
Temperature wd0d 34
I can grab the model like this.
#atactl wd0d identify | awk '/^Model:/{print ($2) }'
ST380021A,
Which leaves me with a pesky comma, or with sed.
#atactl wd0d identify | sed -n '1{
h
s/^Model://
s/, .*$//
p
}'
 ST380021A


I am only *weakly* familiar w/ GNU awk, where the above works.


awk's printf would expect to begin with format like C's printf. The standard idiom is to use '{print $8}', but then if you want to do more, you have to remember
both the parens, and the commas, so now I always do '{print ($8)}' .




Home | Main Index | Thread Index | Old Index