如何使用Bash脚本遍历两个文件 [英] How to use Bash script to loop through two files

查看:85
本文介绍了如何使用Bash脚本遍历两个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下名称的文件(file_in.txt):

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

,我还有另一个文件(file_out.txt),其名称为:

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

现在我想要这样的语句

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 

基本上,我想遍历每个file_in.txtfile_out.txt并将-in-out的值分别替换为ij.

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.

我已经在Bash中尝试了它,但是它似乎不起作用:

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

推荐答案

paste可能会有所帮助:

#!/bin/bash

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

产量:

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

这篇关于如何使用Bash脚本遍历两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆