text: user2155: I have a bam file with Unique Molecular Identifiers (UMIs) for each read present on the RX tag ( such as RX:Z:TGAGAAGGG), as expected by picard and fgbio tools.
  However, several other tools (such as UMI-tools) expect the UMIs to be present at the end of the read name, such as (NB501943:73:HK333BGXC:3:12402:20313:16437_TGAGAAGGG).
  Does anyone know of a tool to do this?
  I have an awk solution which I'll self-answer with, but I don't know whether that is robust.
  
  user2155: My current solution is (awk is not a tool I'm very familiar with, so this may not be good awk code, there is presumably a way to get it to print the header lines unmodified.):
  samtools view -H temp.sam > temp2.sam
  samtools view temp.sam | 
  awk '{OFS = "\t"} {for(i=1;i<=NF;i++)  if ($i ~ /^RX:Z:/) {$1=$1"_"$i; gsub("RX:Z:","",$1); print}}' >> temp2.sam
  
  This seems to work when I test it, but I don't know if I'm missing anything.
  
original_text: 2155: <p>I have a bam file with Unique Molecular Identifiers (UMIs) for each read present on the RX tag ( such as <code>RX:Z:TGAGAAGGG</code>), as expected by picard and fgbio tools.</p>
  <p>However, several other tools (such as UMI-tools) expect the UMIs to be present at the end of the read name, such as (<code>NB501943:73:HK333BGXC:3:12402:20313:16437_TGAGAAGGG</code>).</p>
  <p>Does anyone know of a tool to do this?
  I have an <code>awk</code> solution which I'll self-answer with, but I don't know whether that is robust.</p>
   2155: <p>My current solution is (<code>awk</code> is not a tool I'm very familiar with, so this may not be good <code>awk</code> code, there is presumably a way to get it to print the header lines unmodified.):</p>
  <pre><code>samtools view -H temp.sam &gt; temp2.sam
  samtools view temp.sam | 
  awk '{OFS = &quot;\t&quot;} {for(i=1;i&lt;=NF;i++)  if (<span class="math-container">$i ~ /^RX:Z:/) {$1=$1"_"$i; gsub("RX:Z:","",$</span>1); print}}' &gt;&gt; temp2.sam
  </code></pre>
  <p>This seems to work when I test it, but I don't know if I'm missing anything.</p>
  