I have an alignment file for a protein encoded by about ~3000 bases (I have both bam and sam files), and I am looking to extract all the reads that from bases 877-981. Is there any way to do this with samtools?

I tried using this command:

    samtools view 8.2alnCorrected.bam "877-981" > filteredreads.bam

However I got this message with an empty file:

    region "877-981" specifies an unknown reference name. Continue anyway.
You need to specify the chromosome or contig as well. Your bam will have lines that look like:

    chr1     12345    ...

So for reads are mapped to that chromosome or contig, you want:

    samtools view 8.2alnCorrected.bam chr1:877-981