Hi,

Imagine that I have 20 bam files, which I want to change their header then merge them and then sort them! So I just wondering if these two scenarios make different output :

1. reheader (each of them) -> merge all -> sort the output
2. merge all -> reheader the output -> sort

All bam files have the same read group, and I want to add sample name to each RG field

    @RG     ID:1120

Thanks
It shouldn't make any difference, but what I'd suggest doing is using `samtools merge` and passing the header you want to apply to the merged file through the `-h` argument. That will simplify your workflow. `samtools merge` does expect your input to be already sorted though. If your input is indeed sorted, then that will allow you to accomplish your goal with a single command.

For example, put the header you want in a file called `header.sam`:

    samtools merge -h header.sam merged.bam 1.bam 2.bam 3.bam ... 20.bam