How to use Bash script to loop through two files

后端 未结 3 1699
时光取名叫无心
时光取名叫无心 2020-12-06 21:59

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.ann         


        
相关标签:
3条回答
  • 2020-12-06 22:29

    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
    
    0 讨论(0)
  • 2020-12-06 22:41

    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.

    0 讨论(0)
  • 2020-12-06 22:45

    Use While

         While read line 
         do 
           line=$(echo -ne $line | sed or awk)
         done < Directory/filename.t
    
    0 讨论(0)
提交回复
热议问题