Hi,
I have a text file formated as below:
yannick 2 1 5 2 1 0 3 1 6 8
anna 0 0 0 0 0 0 1 0 0 0
paul 2 0 0 0 0 0 0 0 0 0
bob 3 1 0 2 3 6 4 8 6 4
holyanna 4 0 0 0 0 0 0 0 0 0
samantha 0 0 0 0 0 5 0 0 0 0
richard 0 1 0 0 0 0 0 0 0 0
fred 0 0 3 0 0 0 0 0 0 0
tony 1 0 0 0 0 0 0 0 0 0
steve 4 2 0 5 6 2 0 0 0 0
andrea 0 0 0 0 0 0 0 2 0 0
bill 0 0 0 0 0 5 0 0 0 0
and I want to comptabilise how many times an unique single value appear on each line, so i used this code to do that:
{
for(x=1;x<=2;x++){
cpt=tot=0
for(i=2;i<=NF;i++){
tot+=$i
if($i==x){cpt++}
}
if(cpt==1 && tot==x){tab[x]++;cpt=tot=0}
}
}
END{
for(j in tab){
print j, " : ", tab[j]
}
}
is there another way more valuable to perform it ?
I have a text file formated as below:
yannick 2 1 5 2 1 0 3 1 6 8
anna 0 0 0 0 0 0 1 0 0 0
paul 2 0 0 0 0 0 0 0 0 0
bob 3 1 0 2 3 6 4 8 6 4
holyanna 4 0 0 0 0 0 0 0 0 0
samantha 0 0 0 0 0 5 0 0 0 0
richard 0 1 0 0 0 0 0 0 0 0
fred 0 0 3 0 0 0 0 0 0 0
tony 1 0 0 0 0 0 0 0 0 0
steve 4 2 0 5 6 2 0 0 0 0
andrea 0 0 0 0 0 0 0 2 0 0
bill 0 0 0 0 0 5 0 0 0 0
and I want to comptabilise how many times an unique single value appear on each line, so i used this code to do that:
{
for(x=1;x<=2;x++){
cpt=tot=0
for(i=2;i<=NF;i++){
tot+=$i
if($i==x){cpt++}
}
if(cpt==1 && tot==x){tab[x]++;cpt=tot=0}
}
}
END{
for(j in tab){
print j, " : ", tab[j]
}
}
is there another way more valuable to perform it ?