This is a test version of Biostars. For the public version, visit https://www.biostars.org.
HELP with variable assignment in bash loop for

Hi guys,

I'm pretty new in programming, very naive to be honest and I need some help, if possible.

I need to run a couple of commands for different files, and I thought using the loop for would be the best option. However, I don't know exactly how to NOT overwrite the output, I mean, I need one different file as output for each of the input files. I have tried something like:

for i in "file1.vcf" "file2.vcf" do

PASS filtering

grep -e "#" -e "PASS" /home/hpz440/Documents/example/input/$i > /home/hpz440/Documents//example/output/$i_PASS.vcf
echo $i

done

It didn't work. My idea was to use the name of the file in the output file name, so I wouldnt have the problem with overwriting.

Do you have any idea how can I improve this? The next step once this work, would be insert fiile1.vcf, file2.vcf as a list, so I could edit or add other files to analyze.

Thank you!

bash

Could you elaborate on this please :

It didn't work.

Try something like this :

for i in "file1.vcf" "file2.vcf"; do
echo $i;
grep -e "#" -e "PASS" /home/hpz440/Documents/example/input/$i > /home/hpz440/Documents/example/output/${i%.*}_PASS.vcf;
done;

Remove the double // on the output of your command line. Documents//example should be Documents/example

This is not a Forum. It is a question.

Hello yasminsoareslima!

We believe that this post does not fit the main topic of this site.

Not strictly a bioinformatics question (basic shell scripting). Take a look at walkthroughs like https://www.cyberciti.biz/faq/bash-for-loop/ for example. Pay particular attention to `${i}` syntax.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

Thank you for the information and the kind response.

No problems at all.

Sorry,

Yasmin

0 answers

No answers yet.

Log in to answer this question.