|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to pass nawk variable to shell within the same script?
Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it always prints $c as null. Code:
nawk 'BEGIN {
print "|========================================|"
print "| SI No CHECKS STATUS |"
print "|========================================|"
} /^[0-9]/ {
c++;
print "|------------------------------------------|"
printf "| %s ",$0; getline; s=$0; sub(/:.*/,"",s);
if(s=="Passed") ++p; if(s=="Failed") ++f; if((s!="Passed")&& (s!="Failed")||(s==" ") ) ++n;
printf " : %s |\n", s;
print "|------------------------------------------|"
} END {
print "|========================================|"
print "| Total Executed: " c " |"
print "|========================================|"
}' $1
printf "| Total \e[1;35;40m Executed: $c |\n" |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
I would put the code inside the awk script: Code:
nawk 'BEGIN {
print "|========================================|"
print "| SI No CHECKS STATUS |"
print "|========================================|"
} /^[0-9]/ {
c++;
print "|------------------------------------------|"
printf "| %s ",$0; getline; s=$0; sub(/:.*/,"",s);
if(s=="Passed") ++p; if(s=="Failed") ++f; if((s!="Passed")&& (s!="Failed")||(s==" ") ) ++n;
printf " : %s |\n", s;
print "|------------------------------------------|"
} END {
print "|========================================|"
print "| Total Executed: " c " |"
print "|========================================|"
printf "| Total \033[1;35;40m Executed: %s\033[0m |\n", c
}' "$1" |
| The Following User Says Thank You to radoulov For This Useful Post: | ||
Optimus81 (02-04-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks radoulov. It works fine now. can you please tell me how to print the string say "Passed" in green color. my output looks like this : am not sure how to incoporate this in below line(if it's correct) : Code:
if(s=="Passed") ++p; if(s=="Failed") ++f; if((s!="Passed")&& (s!="Failed")||(s==" ") ) ++n; output : Code:
|========================================| |SI No CHECKS STATUS | |========================================| |1)Intercomponents Checking : Passed | ------------------------ >> #how to print this string "Passed" in green color |----------------------------------------------------| |2)OS version Checking : Passed | |----------------------------------------------------| |3)Component registered : Failed | ------------------------------->> #how to print this "Failed" string in red color |----------------------------------------------------| |4)Verify Server Connection : Failed | |========================================| | Total Passed : 2 | | Total Failed : 2 | | Total executed: 4 | |========================================| |
|
#4
|
||||
|
||||
|
Try this: Code:
nawk 'BEGIN {
print "|========================================|"
print "| SI No CHECKS STATUS |"
print "|========================================|"
} /^[0-9]/ {
c++;
print "|------------------------------------------|"
printf "| %s ",$0; getline; s=$0; sub(/:.*/,"",s);
if (s == "Passed") { ++p; _s = "\033[1;32m" s "\033[0m" }
if (s == "Failed") { ++f; _s = "\033[1;31m" s "\033[0m" }
if((s!="Passed")&& (s!="Failed")||(s==" ") ) ++n;
printf " : %s |\n", _s;
print "|------------------------------------------|"
} END {
print "|========================================|"
print "| Total Executed: " c " |"
print "|========================================|"
printf "| Total \033[1;35;40m Executed: %s\033[0m |\n", c
}' "$1" |
| The Following User Says Thank You to radoulov For This Useful Post: | ||
Optimus81 (02-04-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks it works fine now.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pass parameter to nawk from shell script | samer.odeh | Shell Programming and Scripting | 8 | 10-24-2011 06:02 AM |
| pass variable from awk to shell script | user_prady | Shell Programming and Scripting | 3 | 04-17-2008 05:43 AM |
| Is it possible to pass variable from awk to shell script | user_prady | Shell Programming and Scripting | 3 | 12-18-2007 09:06 AM |
| is it possible to pass external variable values to nawk? | swamymns | Shell Programming and Scripting | 1 | 02-02-2006 05:13 AM |
| How to Pass variable to shell Script | sam70 | UNIX for Dummies Questions & Answers | 5 | 08-23-2005 07:27 PM |
|
|