That seems to have worked! Thanks!
• 0 views
•
link
Hello,
I am trying to change the @RG from "ID:i" to "ID:MyFileName" in a number of files using a while read loop. My syntax is as follows:
ls *.sorted.bam|awk -F "." '{print $1}'| while read name; do
samtools view -H $name.sorted.bam| sed 's/ID:i/ID:$name/'|samtools reheader - $name.sorted.bam > $name.sorted_rh.bam;
done
Everything works perfectly except in the reheadered bam file the "ID:i" is replaced with "ID:$name" not the file name. Any ideas about how to fix this? When not in a loop the sed command changes the strings correctly.
Thanks
use double quote instead of single quote
sed "s/ID:i/ID:$name/"
see https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash
That seems to have worked! Thanks!
Log in to answer this question.
This should work as well: