Nawk One Liner to Count Field Combinations

I have text files, fields separated by commas, and there are 115 fields.
I need to use nawk to look at each line, if field $4==10, then count how many times the combination of field $5 and field $11 occur in the file.

I tried the following:

nawk -F, '{if($4==10){tg[$5]++;cd[$11]++,tgcd[$5 $11]++}}END{for(i in tgcd){print i"\t"tgcd}}' *20130226093*

With the following error:

nawk: syntax error at source line 1
 context is
         >>> {if($4==10){tg[$5]++;cd[$11]++, <<< 
nawk: illegal statement at source line 1

I am way out of my depth here. :confused:

Please post sample input and desired output.

1 Like

The comma before tgcd[$5 $11]++ should be a semicolon

I cannot upload a sample text file because it has customer proprietary infomation. Each line has 115 fields ($1 - $115) but fields $5 and $11 would look like so:

4012 1070397
4012 1070397
4014 1070397
4014 1070397
4014 1070398
4014 1070398
4018 1070398
40184 1070398

And I would like the output to say something along the lines of "4012 1070397" combination happened X times, "4014 1070397" combination happened y times, etc.

---------- Post updated at 01:01 PM ---------- Previous update was at 12:46 PM ----------

I can't believe that was the only problem! Maybe I dont suck as bad as I thought, lol.

Thanks so much!

:slight_smile: