based on range assign a value

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting based on range assign a value
# 1  
Old 08-05-2011
based on range assign a value


I have a file with multiple columns of which the first two columns are like

a1_144601_144650    ABC_yellow_144608_16785 
a1_144651_144700     ABC_yellow_144608_16785
a1_144701_144751     ABC_yellow_144608_16785

So Based on column 1 (red values) I need to check if its falling in the range of green values of column 2. If it falls assign a value of true, if not false in 3rd column


a1_144601_144650    ABC_yellow_144608_16785      false
a1_144651_144700     ABC_yellow_144608_16785                true
a1_144701_144751     ABC_yellow_144608_16785                true

I tried to do it in perl but I am stuck at checking the ranges.

Can I do this in awk?

# 2  
Old 08-05-2011
Question Are you missing a digit?

a1_144601_144650    ABC_yellow_144608_16785 
a1_144651_144700     ABC_yellow_144608_16785
a1_144701_144751     ABC_yellow_144608_16785

ok, 144601 is less than 144608, so false
but, 144651 is more than 144608 but less than 16785
OR... is that supposed to be 167850?
# 3  
Old 08-05-2011
144601 is less than 144608, so false
144651 is more than 144608 but less than 16785 (its still falling in between the range of 144608_15785) so it should be true.

As long as the red value in the column 1 falls between the green values range in column 2 it should be true, if not assign false.

Hope this helps.

# 4  
Old 08-05-2011
I am not sure about awk.It can be done easily in Perl.
use File::Copy;
foreach $dd(@aaa)
$dd =~ /a1_(\d*?)_.*?ABC_yellow_(\d*?)_(\d*)/;
if ( $1>$2  && $1<$3 )
	print FH1 "$&"."  "."true"."\n";
	print FH1 "$&"."  "."false"."\n";

Use this file it works.
a1_144600_144650    ABC_yellow_144608_167850  false
a1_144651_144700     ABC_yellow_144608_167850  true
a1_144701_144751     ABC_yellow_144608_167850  true

You can also refer to the blogspot: for perl solutions

Last edited by Franklin52; 08-06-2011 at 05:47 PM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to assign points to variables based on conditions and update specific field

I have been reading old posts and trying to come up with a solution for the below: Use a tab-delimited input file to assign point to variables that are used to update a specific field, Rank. I really couldn't find too much in the way of assigning points to variable, but made an attempt at an awk... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Check unused ports in a given range and assign an open one

Hi. I need to add code to my KSH script to automatically assign an open port number from a pre-defined range to an Oracle listener. Should I use: lsof -i or netstat -vatn or something else? Thanks. (9 Replies)
Discussion started by: user052009
9 Replies

3. Shell Programming and Scripting

Unique entries based on a range of numbers.

Hi, I have a matrix like this: Algorithm predicted_gene start_point end_point A x 65 85 B x 70 80 C x 75 85 D x 10 20 B y 125 130 C y 120 140 D y 200 210 Here there are four tab-separated columns. The first column is the used algorithm for prediction, and there are 4 of them A-D.... (8 Replies)
Discussion started by: flyfisherman
8 Replies

4. Shell Programming and Scripting

Remove duplicate entries based on the range

I have file like this: chr start end chr15 99874874 99875874 chr15 99875173 99876173 aa1 chr15 99874923 99875923 chr15 99875173 99876173 aa1 chr15 99874962 99875962 chr15 99875173 99876173 aa1 chr1 ... (7 Replies)
Discussion started by: raj_k
7 Replies

5. Shell Programming and Scripting

Printing rows based on column range

Hello, I have a file with nearly 57K lines. I want to filter the lines based on the range of values in a column. For e.g. print lines whose 3rd filed is >=0.02. Input file: LOC_Os09g32030 LOC_Os02g18880 0.0200037219149773 undirected NA NA LOC_Os03g58630 LOC_Os09g35690 ... (1 Reply)
Discussion started by: Sanchari
1 Replies

6. 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

7. Shell Programming and Scripting

Search for a specific data in a file based on a date range

Hi, Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application’s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and... (5 Replies)
Discussion started by: svajhala
5 Replies

8. Shell Programming and Scripting

Help with grouping data based on range position

Input file: data_1 1000 1290 data_4 290 234 data_2 1114 1110 data_5 534 999 data_6 900 1050 . . Desired_output_file_1_0_999: data_4 290 234 data_5 534 999 Desired_output_file_2_1000_1999: data_1 1000 1290 data_2 1114 1110 (1 Reply)
Discussion started by: perl_beginner
1 Replies

9. UNIX for Dummies Questions & Answers

How to assign scores to rows based on column values

Hi, I'm trying to assign a score to each row which will allow me to identify which rows differ. In the example file below, I've used "," to indicate column separators (my actual file has tab separators). In this example, I'd like to identify that row 1 and row 5 are the same, and row 2 and row... (4 Replies)
Discussion started by: auburn
4 Replies

10. Shell Programming and Scripting

Report file extraction based on Date range

Hi all, Iam writing a script, which will extract all the files from Start_Date to End_Date. Files are date stamped as YYYYMMDD. For ex: Start_Date='20051001' End_Date='20060331' extract files such as........ ramp_20050810.rpt ramp_20050915.rpt ramp_20051001.rpt ramp_20051010.rpt... (2 Replies)
Discussion started by: ganapati
2 Replies
Login or Register to Ask a Question