I am new to bash and would like to get help how to run for loop.
Here is my question, I have 10 different sorted bam files(*.sorted.bam) and I would like to do indexing for each sorted bam files.
I know how to run it for single file using the command below
samtools index sample.sorted.bam
I would be happy if some one could show me how to run for multiple files
Best, Amare
CodePudding user response:
you can use the for..in loop like this:
for file in *.sorted.bam
do
samtools index "$file"
done
or in a single line:
for file in *.sorted.bam; do samtools index "$file"; done
You can find more information on bash looping constructs here: https://www.gnu.org/software/bash/manual/bash.html#Looping-Constructs