I have some large bam files for a pipeline. But the RAM ran out when I was performing the pipe. Sorting bam will cause fatal bugs to my pipeline and cannot be debuged for now, hence not the solution. The only option is to downsize the input (upgrading the RAM cannot be done for now due to the high expense). 

Then I thought I could split the original bam to several smaller bam files. But I cannot skip the sorting step. E.g. `samtools view` requires sorting and indexing before spliting. 

Is there other way to do this? 

Thank you. 
Using samtools *alone* the bam file needs to be sorted. However at the cost of materializing the actual string values, you can use awk to do this:

```
samtools view -h $bam | awk 'substr($1,0,1) == "@" || $3 == "chr1"' | samtools view -hb > chr1.bam
```
etc.