I have the following sed command that change the chromosome name:
for file in /myoldpath/*.bam; do filename=`echo $file | cut -d "." -f 1`; samtools view -H $file | sed -e 's/SN:\([0-9XY]\)/SN:chr\1/' -e 's/SN:MT/SN:chrM/' | samtools reheader - $file > /mynewpath/${filename}_chr.bam; done
My quesion is how to insert the result in a new path while keeping the variable $filename as part of every new file name? It always inserts the result in /myoldpath/ or leterally "filename.chr.bam" in the /mynewpath/.
am i missing something in the syntax of that part $file > /mynewpath/${filename}_chr.bam
?
any help would be appreciated
Try to change filename=echo $file | cut -d "." -f 1; to filename=$(echo $file| rev| cut -d "/" -f 1|rev|cut -d "." -f1 );