Visit Our UNIX and Linux User Community


Number count per number ranges


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Number count per number ranges
# 1  
Old 12-18-2007
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
# 2  
Old 12-18-2007
Code:
nawk  '
{
  arr[substr($1, 1, 4)]++
}
END {
  for (i in arr)
    print i, arr[i]
}' myFile

# 3  
Old 12-18-2007
Number count per number ranges

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. Smilie
Please advise.

Thank you so much.

Best Regards,
Shirley
# 4  
Old 12-18-2007
given a sample input provided I get:
Code:
1236 2
1235 3
1234 4

Pls provide your exact input data using vB Codes
# 5  
Old 12-18-2007
Try this one

cut -c1-4 filename|sort|uniq -c
# 6  
Old 12-19-2007
Bug Number count per number ranges

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. Smilie

Thank you.

Best Regards,
Shirley

Previous Thread | Next Thread
Test Your Knowledge in Computers #720
Difficulty: Medium
Alan Minsky was an adviser on Stanley Kubrick's movie 2001: A Space Odyssey.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print root number between min and max ranges

Hi to all, Please help on the following problem, I'm not where to begin, if awk or shell script. I have pairs of ranges of numbers and I need to find the root or roots of ranges based on min Range and Max ranges Example #1: If min range is 120000 and max ranges 124999, it means that are... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

2. Shell Programming and Scripting

How count number of char?

hello how can i cont number of char with loop coomand? i dont want to use wc or other special command the script should check all word's char. one by one also a counter can handle the number As noted in other threads started today. This is not the correct forum for homework assignments. ... (2 Replies)
Discussion started by: nimafire
2 Replies

3. Shell Programming and Scripting

How to count the number of strings?

Hi, I have a text file as shown below. I would like to count the unique number of connections of each person in the first and second column. Third column is the ID numbers of first column persons and fourth column is the ID numbers of second column persons. susan ali 156 294... (7 Replies)
Discussion started by: mohamad
7 Replies

4. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

5. Shell Programming and Scripting

How to convert multiple number ranges into sequence?

Looking for a simple way to convert ranges to a numerical sequence that would assign the original value of the range to the individual numbers that are on the range. Thank you given data 13196-13199 0 13200 4 13201 10 13202-13207 3 13208-13210 7 desired... (3 Replies)
Discussion started by: jcue25
3 Replies

6. Shell Programming and Scripting

Print numbers between two number ranges

Hi, I have a list.txt file with number ranges and want to print/save new all.txt file with all the numbers and between the numbers. == list.txt == 65936 65938 65942 && 65943 65945 ... (7 Replies)
Discussion started by: AK47
7 Replies

7. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

8. Shell Programming and Scripting

count the number of lines that start with the number

I have a file with contents similar to this. abcd 1234 4567 7666 jdjdjd 89289 9382 92 jksdj 9823 298 I want to write a shell script which count the number of lines that start with the number (disregard the lines starting with alphabets) (1 Reply)
Discussion started by: grajp002
1 Replies

9. Shell Programming and Scripting

File number count

hi all i want to count the number of files in a particlar dir i have wrote the codes as below fileCount= ls | wc -l if then echo " " elif then echo " " fi however when i excute the program there are error happens " unary operator expected" i just woundering fileCount=... (4 Replies)
Discussion started by: cryogen
4 Replies

10. Shell Programming and Scripting

Finding number ranges using grep

Is it possible for me to find numbers in a file by a range using grep? like cat data | cut -f1 | grep <info> Im trying to find information and extract every amount that is less than a number (ie less than 75 or whatever) Is this possible? (2 Replies)
Discussion started by: DKNUCKLES
2 Replies

Featured Tech Videos