does anyone know a quick uinx command to take the first N alignments from a BAM file? I tried viewing it as SAM, with headers, taking first N lines and then piping back to samtools but it fails:
However, this won't give you exactly 1000 records since the samtools header file will take up a few lines:
samtools view little.bam | wc -l
Output:
991
Therefore, I recommend you first check how many lines your header is with
samtools view -H big.bam | wc -l
Then add that to the number of records you want to have in your file. You could probably jam it all together in one big bash command but it's easier to understand what's going on this way.
I think your -b option in the first view is the problem - this tells the output to be binary, you want plain text. Kill that as GWW did below.