Entering edit mode
                    10.4 years ago
        Fluorine
        
    
        ▴
    
    110
    I'm writing a shell script that would convert all my .sam files to .bam files. I'm using a loop for all files in the folder that end with .sam. Now my question is how do I write in the script that the output files will have the same name as the input files, but end with .bam?
strictly speaking, if you want to make sure that there's no other ".sam" string in the filename that could avoid this code to replace the extension, you can always force the string replacement to start from back:
for file in *.sam; do samtools view -bS $file > ${file/%.sam/.bam}; donerather than simply
for file in *.sam; do samtools view -bS $file > ${file/.sam/.bam}; doneThank you! That saved so much time :)