Extract Big and continuous regions

Hi all,
I have a file like this I want to extract only those regions which are big and continous

chr1    3280000 3440000
chr1    3440000 3920000
chr1    3600000 3920000 # region coming within the 3440000 3920000. so i don't want it to be printed in output
chr1    3920000 4800000 
chr1    4080000 4800000 # region coming within the 3920000 4800000 . so i don't want it to be printed in output
chr1    4160000 4360000 # region coming within the 3920000 4800000 . so i don't want it to be printed in output
chr1    4160000 4760000 # region coming within the 3920000 4800000 . so i don't want it to be printed in output
chr1    4360000 4760000 # region coming within the 3920000 4800000 . so i don't want it to be printed in output
chr1    4800000 4920000 # region coming within the 4800000 6160000 . so i don't want it to be printed in output
chr1    4800000 5200000 # region coming within the 4800000 6160000 . so i don't want it to be printed in output
chr1    4800000 5280000 # region coming within the 4800000 6160000 . so i don't want it to be printed in output
chr1    4800000 6160000 
chr1    4920000 5200000 # region coming within the 4800000 6160000 . so i don't want it to be printed in output
chr1    5280000 6160000 # region coming within the 4800000 6160000 . so i don't want it to be printed in output

Finally the below regions could be printed in output

chr1    3280000 3440000
chr1    3440000 3920000
chr1    3920000 4800000
chr1    4800000 6160000

So can anyone help me to get that

The following seems to do what you want:

awk '
$3 > LH {
	D[++c] = $0
	L[c] = $2
	H[c] = LH = $3
}
END {	for(i = c - 1; i > 0; i--)
		if(H > L[i + 1]) {
			for(j = i; j < c; j++) {
				D[j] = D[j + 1]
				L[j] = L[j + 1]
				H[j] = H[j + 1]
			}
			c--
		}
	for(i = 1; i <= c; i++)
		print D
}' file

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

perl -anle 'if($F[2]>$h){ $s{$F[1]} = $_; $h=$F[2] } END{ for(sort keys %s){ print $s{$_} } }' amrutha_sastry.input
chr1    3280000 3440000
chr1    3440000 3920000
chr1    3920000 4800000
chr1    4800000 6160000