I've got 500+ files that I need to change from .bam to .sam so am trying to use samtools. I've done some looking on here and found this answer (Changing file paths outputs within a loop, in a shell script) and modified it to fit my work:
input_files="/scratch/spectre/h/homeTCGA_Data/*.bam"
output_files="/scratch/spectre/h/home/Data_Sam"
for i in $input_files
do
tmp=$(i/scratch/spectre/h/home/Data_Sam)
samtools view -h $i > $(tmp/.bam/.sam)
done
I'm a complete novice at this so I'm assuming that I've made an obvious mistake somewhere. The error I'm getting with this is that the directory 'Data_Sam' doesn't exist along with 'ambiguous redirect'. I've checked and it definitely does exist in scratch. I've also tried this in case I'm way over complicating things:
for i in `ls ${/scratch/spectre/h/home/Data/}/*.bam`
do
samtools view -h <$i >${/scratch/spectre/h/home/Data_Sam}/$i.sam
done
For this I'm getting the error 'bad substitution' for ${/scratch/spectre/h/home/Data/}/*.bam`.
I've also tried the following and get the error 'bad substitution':
for i in "ls ${/scratch/spectre/h/home/Data/}/*.bam";
do filename "${i%%.*}";
samtools view $i ${filename}.sam;
done
Is there any way that I can loop over my 500+ files, change them from bam to sam and store them somewhere new?