I have the below code which is supposed to do 2 things on tab delimited files.
- Calculate the sum of one field for the whole file
- Return the number of records in the file
I am facing 2 problems:
- The calculated total seems fine for some files. But in other files it seems to stop in the middle of the file at some record and doesn't continue forward till the end of file.Is there any special character which AWK is being confused for it to be end of file.
- I get a zero instead of the total number of records for any file
Could someone pls guide me as to what i am doing wrong. Running this through a .bat file in Windows 7
BEGIN { FS="\t" }
{ sum[FILENAME] += $42 }
END
{tr=NR}
{
for (i=1;i<ARGC;i++)
printf "%s %15d %d\n",ARGV[i],sum[ARGV[i]],tr
}
Thanks
Ross