Reputation: 43
I have the following script which calculates the sum of a particular column. i am now trying to also get the number of records. however any combination i try, it gives me a syntax error. I am trying to get the number of records passed to a variable tr below.
BEGIN { FS="\t" }
{ sum[FILENAME] += $42 }
{tr=NR}
END {
for (i=1;i<ARGC;i++)
printf "%s %15d\n", ARGV[i],sum[ARGV[i]],tr>> "output.abc"
}
Upvotes: 0
Views: 101
Reputation: 85845
The format in printf
expects two arguments and you give it three, you want:
printf "%s %15d %d\n",ARGV[i],sum[ARGV[i]],tr
Upvotes: 2