Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
cancel
Showing results for 
Search instead for 
Did you mean: 

awk-o-phile question

Highlighted
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
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.