6

I have a file (file_in.txt) containing these names:

aphid_splitseq.1.fasta.annot.xml
aphid_splitseq.2.fasta.annot.xml
aphid_splitseq.3.fasta.annot.xml
aphid_splitseq.4.fasta.annot.xml
aphid_splitseq.5.fasta.annot.xml

and I have another file (file_out.txt) with these names:

aphid_splitseq_1
aphid_splitseq_2
aphid_splitseq_3
aphid_splitseq_4
aphid_splitseq_5

Now I want statements like this

java -cp *:ext/*: es.blast2go.prog.B2GAnnotPipe -in aphid_splitseq.1.fasta.annot.xml -out results/aphid_splitseq_1 -prop b2gPipe.properties -v -annot -dat 

Basically, I want to loop through each of file_in.txt and file_out.txt and replace the values of -in and -out with i and j respectively.

I have tried it in Bash, but it doesn't seem to work:

for i in `cat file_in.txt`
    for j in `cat file_out.txt`; do
        java -cp *:ext/*: es.blast2go.prog.B2GAnnotPipe -in $i -out results/$j -prop b2gPipe.properties -v -annot -dat
    done
done
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
upendra
  • 2,141
  • 9
  • 39
  • 64
  • This should probably be merged with http://stackoverflow.com/questions/28725333/looping-over-pairs-of-values-in-bash but I'm hesitant to mark them as duplicates at this time. – tripleee May 05 '17 at 07:59

3 Answers3

9

paste can be helpful:

#!/bin/bash

paste file_in.txt file_out.txt | while read if of; do
  echo "-in $if -out $of"
done

yields:

-in aphid_splitseq.1.fasta.annot.xml -out aphid_splitseq_1
-in aphid_splitseq.2.fasta.annot.xml -out aphid_splitseq_2
-in aphid_splitseq.3.fasta.annot.xml -out aphid_splitseq_3
-in aphid_splitseq.4.fasta.annot.xml -out aphid_splitseq_4
-in aphid_splitseq.5.fasta.annot.xml -out aphid_splitseq_5

you can modify this to get the desired behaviour.

perreal
  • 94,503
  • 21
  • 155
  • 181
  • @perreal...it worked man `#!/bin/bash paste files_in.txt files_out.txt | while read if of; do echo "java -cp *:ext/*: es.blast2go.prog.B2GAnnotPipe -in $if -out results/$of -prop b2gPipe.properties -v -annot -dat" done` – upendra Sep 20 '13 at 06:38
0

As long as both your lists are just repetitions of the same kind of name with successive numbers, you shouldn't iterate over files at all. Instead, just count a variable and use that in whatever command you want executed at each step. Example:

COUNT=1
while [ $COUNT -lt 5 ]; do
  mv inputfile$COUNT outputfile$COUNT
  let COUNT++
done
Kilian Foth
  • 13,904
  • 5
  • 39
  • 57
-3

Use While

     While read line 
     do 
       line=$(echo -ne $line | sed or awk)
     done < Directory/filename.t
rmaan
  • 79
  • 1
  • 8