Create range of values and count values.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create range of values and count values.
# 8  
Old 11-15-2016
RudiC,
I will try
# 9  
Old 11-17-2016
Hi, I am trying to use this code to solve the problem but it does not work. Smilie
Code:
awk '{if(!X[$1]++){FIR=FIR?FIR"_"$2:$2} {Y[$1]=$1;Z[$2]++}}END{n=split(FIR,FCL,"_");for(i=1;i<=n;i++){s=s?s"\t"FCL[i]:"\t"FCL[i]} print s; for(j in Z){s=j;for(i=1;i<=n;i++){split(FCL[i],PK," ");p=Y[PK[1],PK[2],j]?Y[PK[1],PK[2],j]:0;s=s"\t\t"p};print s}}'

---------- Post updated at 06:51 AM ---------- Previous update was at 06:49 AM ----------

input
Code:
1 15.3
1 15.5
2 15.8
2 15.9
3 16.0
3 16.1
4 16.8
4 17.0
5 17.5
6 18.0
1 18.0
10 17.1

output desired
Code:
       15.0 - 15.9   16.0 - 16.9   17.0 - 17.9   18.0 - 18.9 
1           2             0             0             1
2           2             0             0             0
3           0             2             0             0
4           0             2             0             0
5           0             0             1             0
6           0             2             0             1
10          0             0             1             0

# 10  
Old 11-17-2016
Hmmm - try
Code:
awk '
        {A[$1]
         B[int($2)]
         C[$1,int($2)]++
        }
END     {for (b in B) printf "\t%d.0 - %d.9", b, b
         printf ORS
         for (a in A)   {printf "%s", a
                         for (b in B) printf "\t%d", C[a,b]
                         printf ORS
                        }
        }
'  file
	15.0 - 15.9	16.0 - 16.9	17.0 - 17.9	18.0 - 18.9
10	0	0	1	0
1	2	0	0	1
2	2	0	0	0
3	0	2	0	0
4	0	1	1	0
5	0	0	1	0
6	0	0	0	1

This User Gave Thanks to RudiC For This Post:
# 11  
Old 11-17-2016
Thanks a lot RudiC
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract repetead values in date range

Gents, Using the following values: 3687650458 08/29/2017 1.67581 3687650388 08/29/2017 1.67581 3687650330 08/29/2017 1.67581 3687650330 08/29/2017 1.67581 3687650330 08/28/2017 2.67581 3687650330 08/28/2017 2.67581 3687650330 08/27/2017 3.67581 3687650330 08/27/2017 3.67581 3687650330... (6 Replies)
Discussion started by: jiam912
6 Replies

2. Shell Programming and Scripting

Find values within range and output

Dear All, I am stacked and I ask for your help. Briefly, I have two files, one like this one (file1): 1 101 5 1 102 6 1 103 2 1 104 9 1 105 10 2 301 89 2 302 4 2 303 13 2 304 34 2 305 1 and the other like this one (file2): 1 103 2 303well, what I am trying to do is obtain a... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

3. Shell Programming and Scripting

Convert Column Values to a Range of Values

I have a list of columns with values that I need to transform into a row containing the range of each column. For example: "Column A" 1 2 3 4 10 12 14 15 16 17 18 "Column B" 1 4 5 6 (4 Replies)
Discussion started by: newbio
4 Replies

4. UNIX for Dummies Questions & Answers

Using ls command to display files for range of values only

Hi Forum. I tried to search the forum for an answer but couldn't find it. I have the following files in my directory: PROFILE_TXN_61647.dat PROFILE_TXN_61648.dat PROFILE_TXN_61649.dat PROFILE_TXN_61650.dat PROFILE_TXN_61651.dat PROFILE_TXN_61652.dat PROFILE_TXN_61653.dat... (8 Replies)
Discussion started by: pchang
8 Replies

5. Shell Programming and Scripting

AWK Sorting with range values

Hello, I am looking for some help on GAWK script. I have a list of phone numbers as below. I need to sort these in the range of first 6 digits. 2402170338 2402170387 2402170478 2402170744 2403100025 2403100026 2403100027 2403100028 So for the above sample data, I require an output... (9 Replies)
Discussion started by: Diwakar9
9 Replies

6. Programming

grepping a range of values

I need to return all records in a file starting with a row that says TABLE: <tabl name> lists of hexadecimal records TABLE: <some table> TABLe is a key word in the file. I know the name of the table I want to start with. I do not know the name of the table that I will end with. I just... (4 Replies)
Discussion started by: guessingo
4 Replies

7. Shell Programming and Scripting

Average values in a column based on range

Hi i have data with two columns like below. I want to find average of column values like if the value in column 2 is between 0-250000 the average of column 1 is some xx and average of column2 is ww then if value is 250001-5000000 average of column 1 is yy and average of column 2 is zz. And my... (5 Replies)
Discussion started by: bhargavpbk88
5 Replies

8. Programming

Finding range of values in an array

I have an array containing distances in ascending order, for example: distances = 100 120 150 170 200 280 300 .... I have a number, let's say v = 170 and a variation value, let's say var = 100 . I want to return the array indexes for which the distances cover the range (v - var) to (v +... (3 Replies)
Discussion started by: kristinu
3 Replies

9. Shell Programming and Scripting

Awk extract a range of values

Hi Input 10 131 11 179 11 170 20 142 20 131 20 144 21 178 22 155 22 196 23 144 23 184 24 194 24 191 24 218 25 167 25 131 26 189 (6 Replies)
Discussion started by: genehunter
6 Replies

10. Shell Programming and Scripting

To Create range of values

Hi, I have a file with the below like values with integers only in sorted order (May or may not be in sequence) Eg: File1.txt ----------- 1 2 3 4 5 6 . . . . . 10000 My requirement here is to create a range of values out put to a temp k (4 Replies)
Discussion started by: shiva447
4 Replies
Login or Register to Ask a Question