执行一次bash脚本100次

时间:2015-05-14 17:56:00

标签: bash

我正在编写一个shell脚本来选择从fastq文件中随机选择200000行(Reads_qc.fastq),在较小的文件(file1.fastq)上运行python脚本(counts.py)并计算行数由python脚本生成的输出文件(摘要)。 这是我的代码,

cat Reads_qc.fastq |awk '{ printf("%s",$0); n++; if(n%4==0) { printf("\n");} else { printf("\t\t");} }' |shuf  |head -n 200000 |sed 's/\t\t/\n/g' |awk '{print $1 > "file1.fastq"}'

python counts.py file1.fastq > summary

wc -l summary

你能否建议我如何使脚本100次完成这些操作。

1 个答案:

答案 0 :(得分:0)

您可以使用while循环,并使用'>>'将每个结果附加到摘要文件中运算符而不是'>':

#!/bin/sh

count=100

while [ $count -lt 100 ]
do
    cat Reads_qc.fastq |awk '{ printf("%s",$0); n++; if(n%4==0) { printf("\n");} else { printf("\t\t");} }' |shuf  |head -n 200000 |sed 's/\t\t/\n/g' |awk '{print $1 > "file1.fastq"}'
    # Append to summary file instead of overwrite.
    python counts.py file1.fastq >> summary
    count=`expr $count + 1`
done