I have paired-end sequencing reads and two ends of a read may not come from the same region. I want to extract those that have at least one end mapping on a certain region of the genome.
I have found the following command. But it seems that this command does not extract the read whose one end falls within the region while the other one does not.
samtools view input.bam "Chr10:18000-45500" > output.bam
I think
bedtools pairtobed
can do what you want.