Counting under some condition

I want to develop a shell script but with a bit complicated conditions. I have a file contains a data. The data change every 5 mins.
If the file having data repeated 3 times then add 5 to the counter. By using crontab I will let the script check the file again and if the same 3 data are exist then add another 5 till it reach to 40. Another condition if one of the check dose not have the same repeatative data then the counter should be reset. We may have more than one repetative data then another counter should be start.
ex. file name is ( Main ) and the data is as follow:
NBB001
NBB001
NBB001
TTF033
and because the data changes we might have another data like

NBB001
BFG123

and another ex.
NBB001
NBB001
NBB001
TTF033
TTF033
TTF033

what I want basicly is to have counter running every time i check the file and if it reach to 40 then do some command and if reach 60 do another command. As above if data not continusly available the ounter should be reset and if there is more than one data repeated 3 times then another counter should work.

Appreciate your help

I dont think I understand exactly what you are asking for. Does the data have to occur one after other or can there be other information between two similar lines?
Try "grep -c <data> <Filename>" if that helps

yes the grep will count how many times similar data repeated but I want if its repeated 3 times then count 5 and then atfer 5 mins by using crontab I will re-access the file and check if it has repeatative data occur or not till it reach counting 40.

example

time 12:00 the file (main) has a data as follow:

BBB111
BBB111
BBB111
TNG877
NNT555
SDF990
SDF990
SDF990

The script should count 5 for BBB111 and store it and count 5 for SDF990 and store it

time 12:05 the file main has a data as follow:
BBB111
BBB111
BBB111
TNG877
NNT555

The script will add another 5 for BBB111 which will 10 adn it will reset the counter for SDF990 to zero.
if BBB111 continue appear into file till count reach 40 then do some command.

thanx

---------- Post updated 02-05-10 at 09:31 AM ---------- Previous update was 02-04-10 at 01:50 PM ----------

Any idea...
Appreciate your assist