Link to home
Start Free TrialLog in
Avatar of d_asselin
d_asselinFlag for Canada

asked on

awk variables

Hi

 I’m thring to pass a variable to awk or nawk with no success

I need to find the proper syntax to do this one liner. A bit of
Help would be nice¿


svcs -a | grep finger |  nawk -v HN='hostname' '{print "\$HN\""$1"\",\" " "yes" "\",\" " $3"\" "}'
 which produces
$HN"online"," yes"," svc:/network/finger:default"

But what I need to produce is this
 “servername”,”  online"," yes"," svc:/network/finger:default"

And even the “yes” is not ok it should be a eval  if the second field = online it should be No
                                     And correspondingly the field is disable the field should be no
Like the examples below
“servername”,”  online"," No"," svc:/network/finger:default"

“servername”,”disable ","yes"," svc:/network/finger:default"

Dan
ASKER CERTIFIED SOLUTION
Avatar of gremwell
gremwell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of d_asselin

ASKER

Thank you
  but no kandy I tried that
-bash-3.00# svcs -a | grep finger |  nawk -v HN=`hostname` '{print "\$HN\""$1"\",\" " "yes" "\",\" " $3"\" "}'
with this result

$HN"online"," yes"," svc:/network/finger:default"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yup that works fine
 now! how do you do a eval ?
 if the second field = online the 3 field should be a NO
 and if the second field is disable then I should be a yes

svcs -a | grep finger | nawk -v HN="`hostname`" '{print "\"" HN "\",", "\""$1"\"", "\"yes\", \""$3"\""}'
"cdpqda", "online" "yes", "svc:/network/finger:default"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hum...
Strange stuff…

 The output I’m getting is not correct but I can’t find the error
svcs -a | grep finger |  nawk -v HN=`hostname` '{if ( $2 == "online" ) {print "\""HN"\", \""$1"\", \"" "yes" "\", \""$3"\" "} else {print "\""HN"\", \""$1"\", \"no\", \""$3"\" "} }'

"-s", "online", "no", "svc:/network/finger:default"  

I don’t know where that  -s is coming from.  I removed it from the line because this
Is a Solaris 10 box and hostname  -s is not a supported option in Solaris  I should
have the server name in lieux of -s
Dan
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial