Pattern Matching Count Urgent

The input is like

NO Code
030019991 22
030087819 0
030089001 22
030178901 39
030333333 22

Patterns i want to match is 0300 0301 0303. i want to count different Codes occurances for each of these pattern. for example for 0300 Code 22 occurs 2 times and 0 occurs 1 time. output should be like that

300:
22 2
0 1
0301:
39 1 etc
I have large no of patterns so i have to save them in array and then match them . Please can someone provide with the shell script urgently.

The following is based on the small sample file provided:

> cat patt_file | cut -c1-4,10-12 | sort | uniq -c
      1 0300 0
      2 0300 22
      1 0301 39
      1 0303 22

You might need to play with the layout, but the output is
count pattern code

it works fine but matching Patterns may not be 4 digit in lenght that may be 2,5 or 7 etc. Alse file is csv and much more colums may be present between code 22 etc and No 0300... . I will much appreciate your help

Can you include a sample of the datafile? Perhaps first ten lines or so?

Since you say csv, then you can cut by field rather than character positions - thereby addressing your concern about field length.

i have written the script in cshell but there is another problem that when define variables in a file then run the file error ocurrs something like
missing )
e:g >>cat abc
set a =0;
set xyz =(1 2 3 4 5 6);
>> chmod 777 abc;
>>abc
missing parameter )
how can i correct this. I will much appreciate your help.

You are not defining 'pattern' - you gave an example of four digits out of eight at the start of a line.

Assuming the first column is a pattern - any combination of digits/letters:

awk '{ arr[$1]++ }
       END { for (i in arr) { print i, arr} } ' filename

ok thnk