Thanks, Shawn. It works.
Hello guys. Can you please help out?
I have a directory with multiple sub-directories that contain bam files. I try to count the number of reads for the different bam files recursively and generate count files with the unique bam file names using the command below:
for i in */*bam; do bedtools multicov -bams $i /data/reference/bedfiles/bed1.bed > /data/results/test/${i}; done
I get:
-bash: /data/results/test/sample1/sample1.txt: No such file or directory
-bash: /data/results/test/sample1/sample2.txt: No such file or directory
...
What am I missing?
Your help is appreciated
1 answer
The error is saying that the output file or directory does not exist. This is likely due to how you're calling the filenames. In your for loop you're using two wildcards, one for the directory and one for the filename. Therefore, in your out file when you specify ${i} your computer is again seeing both the directory and filename.
I assume you want your output file to be: /data/results/test/sample1.txt, but ${i} corresponds to sample1/sample1.txt, so it's trying to make a file called /data/results/test/sample1/sample1.txt, which I'm guessing corresponds to a directory that doesn't exist.
Instead I would name your outfile: /data/results/test/$(basename $i). Using the basename function will remove the directory name from the variable $i.
Log in to answer this question.