I'm trying to do a bash loop to run a simple process over all files with extension .sam that can be found on a directory and its subdirectories, and use the same name (exc extension) for the output as its input, with output directed to the same folder in which the input was found.
I got to the following:
for file in $(find ~/data/finch_data/combruns_BF_genomes -name "*.sam" -type f); do
name="${file%.sam}"
dir=$(pwd $file)
samtools view -Sb "$dir"/"$name".sam > "$dir"/"$name".bam
done
but I'm getting this message:
...
>bash:/home/madzays/qsub//home/madzays/data/finch_data/combruns_ZF_transcriptomes/ZBND81X_gff/filteredfirstZBND81X_gff.bam: No such file or directory
>bash:/home/madzays/qsub//home/madzays/data/finch_data/combruns_ZF_transcriptomes/ZBND81X_gff/filteredsecZBND81X_gff.bam: No such file or directory
>bash:/home/madzays/qsub//home/madzays/data/finch_data/combruns_ZF_transcriptomes/ZBND82V_gff/filteredfirstZBND82V_gff.bam: No such file or directory
...
What could be wrong? thanks
/home/madzays/
twice, which should be incorrect.dir=$(pwd)
not dir=$(pwd $file), but it's not the issue heresamtools view -Sb "$name.sam" > ...
(without $dir)