I have some bam files that I want to split.  The reference genome has 22 chromosomes and a bunch of unplaced scaffolds.  I can easily split the bam files chromosome by chromososme

    samtools view my.bam chromsosmeI -b -o my_chromosomeI.bam

I can do the same *scaffold by scaffold*, but I would like to do extract all scaffolds with some sort of wild card (there are a *lot* of them) and have them all in the same bam output.  The wild card part is the one I'm having issues.


    samtools idxstats in.bam | cut -f1 | grep <grepForScaffoldNames> | xargs samtools view -o scaffolds.bam in.bam