<p>For example i have the following already in the <a href='http://samtools.sourceforge.net/SAM1.pdf'>bam</a> header:</p>

<pre><code>@RG    ID:110131_SN107_0398_A81DDCABXX_LANE2    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE4    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE6    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE8    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE2    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE4    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE6    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE8    PL:ILLUMINA    LB:P0007    SM:tumor
</code></pre>

<p>i want to make it:</p>

<pre><code>@RG    ID:110131_SN107_0398_A81DDCABXX_LANE2    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE4    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE6    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE8    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE2    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE4    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE6    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE8    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
</code></pre>

<p>Thanks.</p>

    samtools view -H mybamfile.bam | sed -e 's/LB:/LB:tumor_/' | samtools reheader - mybamfile.bam > mybamfile.reheadered.bam