Re: awk-o-phile question (182 Views)
Reply
Honored Contributor
Chris Vail
Posts: 704
Registered: ‎06-04-2001
Message 1 of 7 (182 Views)

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
Honored Contributor
Tim Nelson
Posts: 3,727
Registered: ‎06-01-2000
Message 2 of 7 (182 Views)

Re: awk-o-phile question

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

cmviewcl|awk '/'$NODENAME'/ { print $9 }'
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 7 (182 Views)

Re: awk-o-phile question

Hi Chris:

# NODENAME=whatever

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

Regards!

...JRF...
Honored Contributor
Chris Vail
Posts: 704
Registered: ‎06-04-2001
Message 4 of 7 (182 Views)

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.
Honored Contributor
Tim Nelson
Posts: 3,727
Registered: ‎06-01-2000
Message 5 of 7 (182 Views)

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

Honored Contributor
Chris Vail
Posts: 704
Registered: ‎06-04-2001
Message 6 of 7 (182 Views)

Re: awk-o-phile question

Thanks Tim...that last syntax is perfect.
Honored Contributor
Tim Nelson
Posts: 3,727
Registered: ‎06-01-2000
Message 7 of 7 (182 Views)

Re: awk-o-phile question

Don't forget the point assignment ;)

Much appreciated.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.