find frequency


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find frequency
# 1  
Old 08-15-2012
find frequency

Hi,

I have a file with more than 1 million records.. Each row has a distance number.. I want to know how many times is each number occurring from min to max number..

Code:
2
5
120
208
7
28
45
6
33
120
7
208
so onn..

output
0-0
1-0
2-1
3-0
4-0
5-1
6-1
7-2
so on 208-2

Thanks,
# 2  
Old 08-15-2012
Code:
awk '{count[$1]++}END{for(j in count) print j,"- "count[j]""}' yourfile.txt


Last edited by codecaine; 08-15-2012 at 08:49 PM..
# 3  
Old 08-15-2012
Try this:
Code:
 
awk '{
 c[$1]++; 
 if($1 < min) min=$1; 
 if($1 > max) max=$1;
}END{
  for(i=min; i<=max; i++){
     print i "-" (c[i]?c[i]:0) }
}' freqData.txt

# 4  
Old 08-16-2012
Code:
awk 'BEGIN{max=0}{
c[$1]++;
if($1 > max){max=$1}
}
END{for(i=0;i<=max;i++)
	{ print i"-"(c[i]?c[i]:0)
	}
}' filename

# 5  
Old 08-16-2012
Try this very simple approach:
Code:
sort -n filename|uniq -c

if you can afford losing the zero occurrences.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

frequency count using shell

Hello everyone, please consider the following lines of a matrix 59 32 59 32 59 32 59 32 59 32 59 32 59 32 60 32 60 33 60 33 60 33 60 33 60 33 60 33 60 33 60 33 60 33 (7 Replies)
Discussion started by: xshang
7 Replies

2. Shell Programming and Scripting

Bash - Same frequency

Hi, Could anyone help me with the following question, if I have two colums (names and frequency) as follows in a file called name.txt Michael 1 Jones 1 Ben 2 Rebeca 4 David 1 and I want to use bash script called freqnames.sh that takes one argument (name) and the output should be... (3 Replies)
Discussion started by: jboy
3 Replies

3. Shell Programming and Scripting

Calculating cumulative frequency

Hi, I have a file containing the frequency's of an element sorted in ascending order. The file looks something like this: #Element Frequency 1 1 2 1 3 1 4 1 5 1 6 ... (5 Replies)
Discussion started by: sajal.bhatia
5 Replies

4. Shell Programming and Scripting

Sorting value frequency within an array

How is it possible to sort different nummeric values within an Array. But i don`t want the highest or the lowest. I need the most frequently occurring value. For examble: My Array has to following values = (200 404 404 500 404 404 404 200 404) The result should be 404 The values are... (3 Replies)
Discussion started by: 2retti
3 Replies

5. Shell Programming and Scripting

Counting commands frequency

I'd like to create a script that keeps track of the commands used. For example: count ls ps and from now on whenever I use ls or ps a counter is increased. I want that after the command count has been activated a session starts(here I can use any commands) and I want to stop the session... (5 Replies)
Discussion started by: Max89
5 Replies

6. Solaris

out of frequency

:cool: after installing solaris 10 5/08/09 directory the computer rebooting then the massage "out of frequency" appear.i want a solution first second my main board is GA-MA780G UD3H (14 Replies)
Discussion started by: medo2008
14 Replies

7. HP-UX

How to find processor frequency

Hello , Please tell me how to find processor frequency in HP UNIX . (8 Replies)
Discussion started by: manjunath
8 Replies

8. Solaris

Monitor shows out of frequency

:confused: :( I had a Intel P4 2.6 HT pc with 256DDRAM. I installed solaris 10 with most of the default configuration by the system...now when i boot the system with solaris 10, after the boot screen is past and desktop login screen is about to appears the monitor goes down and displays "OUT OF... (0 Replies)
Discussion started by: sunilpatwal
0 Replies

9. HP-UX

Frequency of CPU's on HP-UX server

Does anyone know if there is a command in hp-ux to find out the frequencies of the cpus on the server. I know in sun the command is /usr/sbin/psrinfo -v (on Sun)??Thanks (3 Replies)
Discussion started by: lnineill
3 Replies
Login or Register to Ask a Question