gpt4 book ai didi

python - Bash while 循环调用 Python 脚本

转载 作者:行者123 更新时间:2023-11-29 09:49:36 24 4
gpt4 key购买 nike

我想从 Bash while 循环中调用 Python 脚本。但是,我不太了解如何正确使用 Bash 的 while 循环(可能还有变量)语法。我正在寻找的行为是,虽然文件仍然包含行(DNA 序列),但我正在调用 Python 脚本来提取序列组,以便另一个程序(dialign2)可以对齐它们。最后,我将路线添加到结果文件中。注意:我不是要遍历文件。为了使 Bash while 循环工作,我应该更改什么?我还想确保 while 循环会在每个循环中重新检查不断变化的 file.txt。这是我的尝试:

#!/bin/bash
# Call a python script as many times as needed to treat a text file

c=1
while [ `wc -l file.txt` > 0 ] ; # Stop when file.txt has no more lines
do
echo "Python script called $c times"
python script.py # Uses file.txt and removes lines from it
# The Python script also returns a temp.txt file containing DNA sequences
c=$c + 1
dialign -f temp.txt # aligns DNA sequences
cat temp.fa >>results.txt # append DNA alignements to result file
done

谢谢!

最佳答案

不知道你为什么要这样做。

c=1
while [[ -s file.txt ]] ; # Stop when file.txt has no more lines
do
echo "Python script called $c times"
python script.py # Uses file.txt and removes lines from it
c=$(($c + 1))
done

关于python - Bash while 循环调用 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2359896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com