Number count per number ranges

Hi,

I have a question here that need to get advise from all of you. Let say I have a set of data

12347777
12359899
12347677
12360090
12347688
12359979
12359009
12367022
12346677

I need to count the number that appear in each numbering ranges and the output is like below:

Prefix Count
1234 4
1235 3
1236 2

How can I do this by using shell script? What command that I can use? Please advise. Really appreaciate your help. Thank you so much.

Best Regards,
Shirley

nawk  '
{
  arr[substr($1, 1, 4)]++
}
END {
  for (i in arr)
    print i, arr
}' myFile

Hi vgersh99,

I have tested on the script with test data, but no output is showing. The output file is empty. Tried to modify the script, but still the same. :frowning:
Please advise.

Thank you so much.

Best Regards,
Shirley

given a sample input provided I get:

1236 2
1235 3
1234 4

Pls provide your exact input data using vB Codes

cut -c1-4 filename|sort|uniq -c

Hi vgersh99 and ranjithpr,

The script is working now and I able to get the output data that I needed.
Thank you so so so much for your helps. :slight_smile:

Thank you.

Best Regards,
Shirley