Help on counting number of bytes in a field

Hi,

I have a file that has 300 records with a load of fields. two of them are:

field_1 has between 8-9 bytes i.e. 012345678, 0123456789
field_2 has 10 bytes i.e. 01234567890

I want to be able to echo out the total of each of these fields i.e.

200 (have 8 - 9 bytes)
100 (have 10 bytes)

not sure how to do this, I have tried wc -l :

RR="wc -l customer directory/file in.dat"

the file in .dat has a space in the file name? not sure if it makes a difference?

I cannot get this to work?
any help would be appreceiated.

awk '{ arr[length($1)]++; arr[length($2)]++; }
       END {print "8 - 9 bytes", arr[8]+arr[9], " 10 bytes ", arr[10] } ' file

Do not use awk at all so not sure how to write this??

I need two variables that will output the 8 -9 byte total and 10 byte total i.e.

8-9=awk '{ arr[length($1)]++ }
END {print "8 - 9 bytes", arr[8]+arr[9] } ' path for file?
10=awk '{ arr[length($2)]++; }
END {print " 10 bytes ", arr[10] } ' path for file?

Is this how you would use the solution by Jim???
:confused:

It uses associative arrays, to understand how associative arrays work in awk, see this post http://www.unix.com/unix-dummies-questions-answers/31837-unable-understand-associative-nature-awk-arrays.html

About running this awk script, you have to use it in the same way as he coded, its as per your requirements, if you don't know how to run it at command line, then put it in some shell-script and run that file. Something like this:

#! /bin/ksh
awk '{ arr[length($1)]++; arr[length($2)]++; }
       END {print "8 - 9 bytes", arr[8]+arr[9], " 10 bytes ", arr[10] } ' file

Save this shell-script as "test" then do the following:

chmod +x test
./test