1
#!/bin/bash

for i in /home/xxx/sge_jobs_output/split_rCEU_results/*.rCEU.bed
do
intersectBed -a /home/xxx/sge_jobs_output/split_rCEU_results/$i.rCEU.bed -b /home/xxx/sge_jobs_output/split_NA12878_results/$i.NA12878.bed -f 0.90 -r > $i.overlap_90.bed
done

However I got the errors like:

Error: can't determine file type of '/home/xug/sge_jobs_output/split_NA12878_results//home/xug/sge_jobs_output/split_rCEU_results/chr4.rCEU.bed.NA12878.bed': No such file or directory

Seems the computer mixes the two .bed files together, and I don't know why. thx

3
  • I'm slightly confused, because the output doesn't appear to be valid based on the input (homedir different name, directory path different), and when I try the syntax you have, it WFM. Can you double check what you're running and show the exact input/output? Commented Aug 13, 2011 at 21:34
  • thx. My input comes from two different directory.....Maybe this is the problem? Commented Aug 13, 2011 at 21:37
  • I'm not sure, tbh. However, I suspect $i doesn't contain what you think it does. Try this, for example: [for i in /tmp/*.tar; do echo $i; done;] If you run that, you get the full path to the files, not just what the * matched. Therefore, it might return '/tmp/foo.tar'. I suspect what you are therefore most likely going to want to do is run some sed/awk magic to strip out just the small part of the file name that you're interested in. Commented Aug 13, 2011 at 21:40

1 Answer 1

4

Your i has the format /home/xxx/sge_jobs_output/split_rCEU_results/whatever.rCEU.bed, and you insert it to the file name, which leads to the duplication. It's probably simplest to switch to the directory and use basename, like this:

pushd /home/xxx/sge_jobs_output/split_rCEU_results
for i in *.rCEU.bed
do
    intersectBed -a $i -b ../../sge_jobs_output/split_NA12878_results/`basename $i .rCEU.bed`.NA12878.bed -f 0.90 -r > `basename $i .NA12878.bed`.overlap_90.bed
done
popd

Notice the use of basename, with which you can replace the extension of a file: If you have a file called filename.foo.bar, basename filename.foo.bar .foo.bar returns just filename.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks. it works! I don't fully understand what this 'i' refers to!
If it helps, you can try it in a shell, by just writing 'for i in *; do echo $i; done'. You'll see that 'i' simply contains the file names as the shell matches them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.