This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Limiting interval sizes with awk

Kind of a basic awk question. I have a bed file where I have been doing the following to limit interval sizes to those under 1000bp with the following awk script, how would I go about doing the same thing but limiting the output to those between 150-200bp only? Thanks!

awk '{if($3-$2 <= 1000) print}' test.bedpe > test_under1000.bedpe
awk bed bedtools bedops interval

But something like the condition below will not work in awk, will it?

awk '{if(150 <= $3-$2 <= 200) print}' test.bedpe > test_under150_200.bedpe

Many thanks!

Natasha

This seems to work fine:

awk '{if($3-$2 >= 150 && $3-$2 <= 200) print}' test.bedpe > test_between_150-200.bedpe

1 answer

Use awk AND operator:

awk '{if (CONDITION && CONDITION) print}' test.bedpe > test_between_150-200.bedpe

Log in to answer this question.