5

Counting Multiple Fields with awk/nawk

view full story
linux-howto

http://www.unix.com – I am trying to figure out a way in nawk to 1) get a count of the number of times a value appears in field 1 and 2) count each time the same value appears in field 2 for each value of field 1. So for example, if I have a text file with the following: grapes, purple apples, green squash, yellow grapes, green apples, red squash, green, grapes, red apples, yellow squash, green I want to figure out how many times each color occurs for each type of fruit. There may be new fruit thrown in the file from time to time so i don't have a hard-and-fast list of the fruit and would need the (HowTos)