LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-25-2013, 11:11 AM   #1
and_y
LQ Newbie
 
Registered: Aug 2013
Posts: 2

Rep: Reputation: Disabled
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
 
Old 08-25-2013, 11:21 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,951

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by and_y View Post
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.
 
Old 08-25-2013, 11:28 AM   #3
and_y
LQ Newbie
 
Registered: Aug 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
.
 
Old 08-25-2013, 11:40 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Binning datawith AWK bldcerealkiller Programming 4 12-08-2011 04:27 PM
Split a file, byte-wise, not character-wise. stf92 Linux - Newbie 4 11-17-2010 07:43 AM
gnome-terminal is missing one pixel row and its an important row rednuht Linux - General 1 12-24-2009 11:30 AM
how to Block a site in a Firewall or Router by Protocol wise & host wise. shahid khan Linux - Security 2 06-26-2009 05:13 PM
bandwidth allocation by user wise and ip wise basbosco Linux - Networking 1 11-12-2003 03:54 AM


All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration