based on range assign a value

Hello,

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

o/p:

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?

Thanks,

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?

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.

Thanks,

I am not sure about awk.It can be done easily in Perl.

use File::Copy;
open(FH,"<aaa.txt");
@aaa=<FH>;
close(FH);
open(FH1,">>aaa.tmp");
foreach $dd(@aaa)
{
$dd =~ /a1_(\d*?)_.*?ABC_yellow_(\d*?)_(\d*)/;
if ( $1>$2  && $1<$3 )
{
	print FH1 "$&"."  "."true"."\n";
}
else
{
	print FH1 "$&"."  "."false"."\n";
}
}
close(FH1);
move("aaa.tmp","aaa.txt");
unlink("aaa.txt);

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:http://linux-forum-karthik.blogspot.com for perl solutions
:slight_smile: