0

i have a script which depends on 3 variables. such as this:

#!/bin/bash
/home/sugi/Desktop/rtg-tools-3.5.1/rtg vcfeval -b $1 -c $2 -t /home/sugi/Desktop/hg19.sdf --sample $3 -f AVR -o /home/sugi/Desktop/eval_{$3}
exit

I want to execute this script on a list of samples. for that i have 3 files containing the location of the samples and the sample names. for each entry of the files the above command should run. each of the files have the same number of entries per line.

For that I have tried this:

cat file1.txt file2.txt file3.txt | xargs -i myscript.sh  {} {} {}

however this not work. and I have tried several threads also on stackoverflow such as "xargs with multiple arguments. Appreciate any help. Thx.

JNevill
  • 46,980
  • 4
  • 38
  • 63
ingo
  • 37
  • 6
  • Do you want to loop over the lines in the 3 files in parallel? – melpomene Oct 09 '15 at 14:49
  • use `paste` - http://stackoverflow.com/questions/4011814/how-to-interleave-lines-from-two-text-files – Karoly Horvath Oct 09 '15 at 14:56
  • 1
    @sugsiv What you have does loop over every entry of the files. I don't understand what you're asking for. – melpomene Oct 09 '15 at 15:04
  • unfortunately the output is not the same – ingo Oct 09 '15 at 15:23
  • Welcome to Stack Overflow! If one of the answers worked for you, it would be appreciated if you accept the answer. This will give future readers a clue about the value of the solution. See also this help page: [What should I do when someone answers my question?](http://stackoverflow.com/help/someone-answers) – Jaap Oct 14 '15 at 13:29

2 Answers2

0

If three variables will come from three separate files this should do

while read a b c; do ..your_script_here.. done < <(paste file1 file2 file3)

refer the variables as $a, $b, $c in the body.

karakfa
  • 66,216
  • 7
  • 41
  • 56
0

Combining paste and xargs:

paste file[1-3].txt | xargs -n3 myscript.sh
Walter A
  • 19,067
  • 2
  • 23
  • 43