Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data binning

Status
Not open for further replies.

bldcerealkiller

Technical User
Dec 7, 2011
2
GB
Hi everybody, I'm struggling to find a way out hope you can help me.
I have a file that looks like this

...
5.059259 0
4.892560 2
4.795937 0
4.357734 1
4.432540 0
4.502526 3
4.468403 0
...

The first column ranges from 0 to 8 and the second column from 0 to 4.
Is it possible to count and output the recurrence of the number in the second column within a defined range (let's say 0,5) of the first one?

The final output should look like this:

$1RANGE $2RANGE $3 recurrence/number of hits

[0] [0] [..]
[0,5] [0] [..]
.....
.....
[7] [0] [..]
[7,5] [0] [..]
.....
.....
[0] [1] [..]
[0,5] [1] [..]
......
.....
[7,5] [1] [..]
[8] [1] [..]
....
....
....
....
[0] [4] [..]
[0,5] [4] [..]
....
[7,5 [4] [..]
[8] [4] [..]

Thank you in advance for your reply and sorry if I wasn't too clear.
Regards
 
Hi

As far as I understood the requirement :
Code:
awk '[teal]{[/teal]c[teal][[/teal][COLOR=chocolate]int[/color][teal]([/teal][navy]$1[/navy][teal]/[/teal][purple].5[/purple][teal]),[/teal][navy]$2[/navy][teal]]++[/teal][teal]}[/teal]END[teal]{[/teal][b]for[/b][teal]([/teal]f[teal]=[/teal][purple]0[/purple][teal];[/teal]f[teal]<=[/teal][purple]8[/purple][teal];[/teal]f[teal]+=[/teal][purple].5[/purple][teal])[/teal][b]for[/b][teal]([/teal]s[teal]=[/teal][purple]0[/purple][teal];[/teal]s[teal]<=[/teal][purple]4[/purple][teal];[/teal]s[teal]++)[/teal][COLOR=chocolate]printf[/color][green][i]"[%.1f] [%d] [%d][/i][/green][lime][i]\n[/i][/lime][green][i]"[/i][/green][teal],[/teal]f[teal],[/teal]s[teal],[/teal]c[teal][[/teal]f[teal]/[/teal][purple].5[/purple][teal],[/teal]s[teal]][/teal][teal]}[/teal]' /input/file
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Next time when you ask also post the code you tried so far.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top