user2473726
user2473726

Reputation: 43

AWK. Pass number of records in a file to a variable

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

Answers (1)

Chris Seymour
Chris Seymour

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

Related Questions