Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

please check the syntax of this script

kiran1977
Occasional Contributor

please check the syntax of this script

BEGIN{
FS="|";
}
{

if($26 < 0){na=na+1};
else if ($26 > 0) && ($26 <= 10) {nb = nb+1};
else if ($26 >10) && ($26<20) {nc = nc+1};
else if ($26 > 20) && ($26 < 30) {nd = nd+1};
esle if ($26 > 30) && ($26 < 40) {ne = ne+1};
else if ($26 > 40) && ($26 < 50) {nf = nf+1};
esle ($26 > 50) {ng=ng+1} }
END {print na, nb, nc, nd, ne, nf, ng, nh, ni, nj}
2 REPLIES
Kent Ostby
Honored Contributor

Re: please check the syntax of this script

The problem is the ";"

The middle part should be:

if($26 < 0){na=na+1}
else if ($26 > 0) && ($26 <= 10) {nb = nb+1}
else if ($26 >10) && ($26<20) {nc = nc+1}
else if ($26 > 20) && ($26 < 30) {nd = nd+1}
esle if ($26 > 30) && ($26 < 40) {ne = ne+1}
else if ($26 > 40) && ($26 < 50) {nf = nf+1}
esle ($26 > 50) {ng=ng+1} }


"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
H.Merijn Brand (procura
Honored Contributor

Re: please check the syntax of this script

There is no coverage of 20, 30, 40, and 50
There are far too many semi-colons

if ($26 < 0) { na = na + 1 }
else if ($26 < 10) { nb = nb + 1 }
else if ($26 < 20) { nc = nc + 1 }
:
:
else { ng = ng + 1 }

or in perl

$n[$F[25]<0?0:$F[25]>50?7:1+int($F[25]/10)]++;
END{print @n[0..7]}

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn