I want to make a loop to run over multiple input files and produce one output file per input file.
I can use this command to make 1 output bam files, from 1 input sam file:
samtools view -S -b -h $input_file > $output_file
where:
input_file="/scratch/RNAseq/hisat2_alignment/456.sam"
output_file="/scratch/RNAseq/BAM_files/raw_BAM/456.bam"
When making this command into a loop I am unsure of what to do with the $output_file
equivalent. Because I don't know how to make the file path and file extension change required for the $many_output_file variable
:
many_input_files="/scratch/RNAseq/hisat2_alignment/*.sam"
for i in $many_input_files
do
samtools view -S -b -h $i > $many_output_file
done
Can anyone help please? I am new to Bash, I usually use R. I have tried using sed and tr but they seem to come up with errors when I try to make the file list of many_output_file
from many_input_files