Operating System - HP-UX
1752618 Members
4615 Online
108788 Solutions
New Discussion юеВ

add unix command in with in awk

 
ashan
Advisor

add unix command in with in awk


Hi I need to run unix command (hostname) in awk and grep some fields

ioscan -kf |grep disk |grep NO_HW |awk '{print
$1,$3,$5}

5 REPLIES 5
Bill Hassell
Honored Contributor

Re: add unix command in with in awk

You can save a grep statement by letting ioscan find the disks:

ioscan -kfC disk | grep NO_HW

To pass a value to awk, use -v as in:

ioscan -kfC disk | grep NO_HW | awk -v MYHOST=$(hostname) {print MYHOST": "$1,$3,$5}


Bill Hassell, sysadmin
ashan
Advisor

Re: add unix command in with in awk

Hi Bill,
It working ..How do I assign few variables in
awk.I hope -v can assign for one variable.

shoe me how to do it.

need add uname -r and who -q in the same awk
statement.

Regards

ashan

Duncan Webbe
New Member

Re: add unix command in with in awk

Hi Ashan

From the man page for awk:

"Multiple occurrences of the
-v option can be specified on the awk command line".

Regards

Duncan
Systeemingenieurs Infoc
Valued Contributor

Re: add unix command in with in awk

...|awk -v uname=$(uname -r) -v who=$(who -q) '{ print uname " " who}'
A Life ? Cool ! Where can I download one of those from ?
john korterman
Honored Contributor

Re: add unix command in with in awk

Hi,
if the variables contain spaces, they should be quoted, e.g.:

# echo blahblah| awk -v unr="$(uname -r)" -v whq="$(who -q)" '{print unr "\n" whq}'

regards,
John K.
it would be nice if you always got a second chance