perl -e'$cond=join"||",map{"($_..\$.==$_+2)"}do{local@ARGV=shift;<>};eval"($cond)&&print while<>"' lines test.txt