I have multiple files
on a another server that needs to be downloaded, processed and deleted following by script
. The download url is defined as $FILE
in the script. However, I am not sure how to call the actual filename using $FILE
in my second command samtools
since the filename is the last part of the url and therefore not the same as "$FILE". Any suggestions how to define the filename (which is the part after the last / in the url, indicated as * below) so that I can input and output a unique file in the samtools function, and also delete the same file after processing using rm
.
test.txt
gs://hmf-cram-xfdrvdrv/file123535_dedup.realigned.cram.crai
gs://hmf-cram-dvdvdv/file12353535_dedup.realigned.cram.crai
gs://hmf-cram-evd/file46475754_dedup.realigned.cram.crai
script
#!/bin/bash
mapfile -s 1 -t files < test.txt
echo "${files[@]}"
for FILE in ${files[@]}; do
gsutil -u absolute-bison-xxxx cp $FILE gs://bucket_1
samtools view -@5 -O bam -f 4 *.cram > /home/user/*.unmapped.bam
rm *.cram
rm *.crai;
done