Tag Archives: Total Executed

How to pass nawk variable to shell within the same script?

By Optimus81

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.


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"


Source: FULL ARTICLE at The UNIX and Linux Forums