tiago
tiago

Reputation: 39

awk - sum and evaluate columns sh

I need to evaluate the following file

USER1 256     375     374     463     382     0       0       502
USER2 356     499     369     381     525     0       0       436
USER2 196     375     250     293     450     0       0       458
USER3 16      86      102     0       0       0       0       0
USER4 343     459     310     446     488     0       0       350
USER5 13      246     102     211     190     0       0       119
...
USERn

... where the number of lines must be dynamic (if possible number of columns too), by this way:

  • if the sum of values in column > 0 true else false
  • column 0 not evaluated

and get the following result:

n2  true
n3  true
n4  true
n5  true
n6  true
n7  false
n8  false
n9  true

thanks in advance

Upvotes: 1

Views: 76

Answers (1)

Zombo
Zombo

Reputation: 1

#!/usr/bin/awk -f
{
  for (z=2; z<=NF; z++)
    y[z] += $z
}
END {
  for (z in y)
    print "n" z, y[z] ? "true" : "false"
}

Upvotes: 3

Related Questions