Home > database >  How to name hundreds of files in increasing order in bash?
How to name hundreds of files in increasing order in bash?

Time:02-19

I need to download 300 files on the cloud, and name them one by one in increasing order. I can achieve one time by running the following code. The pathname before '>' is the location of the initial files, the pathname after '>' is where I want to save.

/Applications/samtools-1.14/samtools depth -r dna /Volumes/lab/plants/aligned_data/S1_dedup.bam > /Volumes/lab/students/test1.txt

My question is how to change the numbers in 'S1_dedup.bam' and 'test1.txt' from 1 to 300 in a loop (or something), instead of hardcode the numbers 300 times by hand.

CodePudding user response:

for ((i=1;i<=300;i  ))
do
  /Applications/samtools-1.14/samtools depth -r nda /Volumes/lab/plants/aligned_data/S${i}_dedup.bam > /Volumes/lab/students/test${i}.txt
done

CodePudding user response:

you can use a for loop

for i in {1..300}
do
  /Applications/samtools-1.14/samtools depth -r nda /Volumes/lab/plants/aligned_data/S${i}_dedup.bam > /Volumes/lab/students/test${i}.txt
done
  • Related