LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   binning iteratively row wise (https://www.linuxquestions.org/questions/linux-newbie-8/binning-iteratively-row-wise-4175474640/)

and_y 08-25-2013 10:11 AM

binning iteratively row wise
 
Hi
I have a file some thing like below. I want to bin the data. My Bin size is 100.
Code:

items        number
HELIX1        75
HELIX6        160   
HELIX2        88   
HELIX19        114 
HELIX5        61   
HELIX4        167

it should consider each elemet under the number column and bin all the lines like below with 100 as an interval. The third column should represent the bin range
Code:

bin_75-175.txt
HELIX1        75        75-175         
HELIX2        88        75-175   
HELIX19        114        75-175
HELIX6  160        75-175
HELIX4        167        75-175

Code:


bin_160-260.txt
HELIX6      160        160-260       
HELIX4      167        160-260

Code:

bin_88-188.txt
HELIX2        88        88-188                 
HELIX19        114        88-188
HELIX6  160        88-188       
HELIX4        167        88-188

and so on based on the number of rows in inpit file

TB0ne 08-25-2013 10:21 AM

Quote:

Originally Posted by and_y (Post 5015583)
Hi
I have a file some thing like below. I want to bin the data. My Bin size is 100.
Code:

items        number
HELIX1        75
HELIX6        160   
HELIX2        88   
HELIX19        114 
HELIX5        61   
HELIX4        167

it should consider each elemet under the number column and bin all the lines like below with 100 as an interval. The third column should represent the bin range
Code:

bin_75-175.txt
HELIX1        75        75-175         
HELIX2        88        75-175   
HELIX19        114        75-175
HELIX6  160        75-175
HELIX4        167        75-175

Code:


bin_160-260.txt
HELIX6      160        160-260       
HELIX4      167        160-260

Code:

bin_88-188.txt
HELIX2        88        88-188                 
HELIX19        114        88-188
HELIX6  160        88-188       
HELIX4        167        88-188

and so on based on the number of rows in inpit file

Ok...so post what you've written/tried so far, and tell us where you're stuck, and we can try to help you. But we are NOT going to write your scripts for you.

and_y 08-25-2013 10:28 AM

Code:

awk '{f=sprintf("%d", 1+$2/100); fn[f]="bin"f"_"; print $1,$2>>fn[f]}' file_name
. I don't know how to bin on the basis of interval. Th above code bins from
Code:

0-100,100-200
etc but it wont consider
Code:

75-175
.

grail 08-25-2013 10:40 AM

Well I am not understanding how the ranges are selected, but as your first example also required the data to be sorted, I would suggest storing the necessary data in arrays and then
in the END section you will need to loop over the data and use an 'if' clause(s) or maybe a select / case to allow you to branch the data into the necessary files.


All times are GMT -5. The time now is 12:56 PM.