How to filter a SAM file by a bed file? I have a large BAM file and I want to filter it by just what's defined in a bed file, and write it to a new file.

Is it possible to do this with samtools, and if so, how? Is there a better tool I could use to do this?
Thanks to the helpful comments I figured it out:

samtools view -b -h -L bedfile.bed originalbam.bam &gt; newbam.bam


-b = Output as bed file
-h = include header
-L = only output alignments overlapping the input bed file