1752767 Members
5148 Online
108789 Solutions
New Discussion юеВ

awk-o-phile question

 
Chris Vail
Honored Contributor

awk-o-phile question

Its been 3 or 4 years since I last was logged into ITRC, but my career has recently re-veeredto HP'ish ways. I've been doing things other than HP9000 sysadmin stuff recently, but am now back to carrying a pager and staring at a lot of # prompts.

I have a need to create a script that parses the output of the cmviewcl command. I cannot seem to find a syntax that works. AIX's variant of the grep command has the the -p option that would let me do what I want to do, but HPUX does not support this option.

I want to parse the output of the cmviewcl command and extract the nodename on which a given package s running. The syntax will be something like: cmviewcl|awk '/$NODENAME/ { print $9 }'.

I know there are folx here who know exactly the proper syntax. It has been too long and many synapses joined my hairline in disappearing from the disappearing from this universe--my brain is just not what it used to be (if it ever was).

Chris
6 REPLIES 6
Tim Nelson
Honored Contributor

Re: awk-o-phile question

Assuming NODENAME is set to something then single quote your var.

cmviewcl|awk '/'$NODENAME'/ { print $9 }'
James R. Ferguson
Acclaimed Contributor

Re: awk-o-phile question

Hi Chris:

# NODENAME=whatever

# cmview||awk -v NODENAME=$NODENAME '$0~NODENAME {print $9}'

Regards!

...JRF...
Chris Vail
Honored Contributor

Re: awk-o-phile question

Thanks for your help, guys...I need to clarify the question. I need to extract the package names from the output of the cmviewcl command. It looks something like the following:
NODE STATUS STATE
Nodename1 up running

PACKAGE STATUS STATE AUTO_RUN NODE
Package1 up running enabled Nodename1
Package2 up running enabled Nodename1
Package3 up running enabled Nodename1

I want to pass Package1, Package2, Package3 etc into the commands to be executed in a while-do-done script.
Tim Nelson
Honored Contributor

Re: awk-o-phile question

cmviewcl|awk '$5 ="$NODENAME" { print}'|while read f1 f2 f3 f4 f5
do
echo "$f1"
echo "$f2"
echo "$f3"
...
...

done

Chris Vail
Honored Contributor

Re: awk-o-phile question

Thanks Tim...that last syntax is perfect.
Tim Nelson
Honored Contributor

Re: awk-o-phile question

Don't forget the point assignment ;)

Much appreciated.