Question: (Closed) HELP with variable assignment in bash loop for
0
gravatar for yasminsoareslima
20 months ago by
yasminsoareslima10 wrote:

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 • 321 views
ADD COMMENTlink modified 20 months ago by Joe18k • written 20 months ago by yasminsoareslima10

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

ADD REPLYlink modified 20 months ago • written 20 months ago by Bastien Hervé4.8k

This is not a Forum. It is a question.

ADD REPLYlink written 20 months ago by Joe18k

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!

ADD REPLYlink written 20 months ago by Joe18k
1

Thank you for the information and the kind response.

No problems at all.

Sorry,

Yasmin

ADD REPLYlink written 20 months ago by yasminsoareslima10
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1686 users visited in the last hour