(for x in `cat list` ; do
do_something $x
done) | process_output
被替换为此
cat list | parallel do_something | process_output
我正在尝试在这上面实现它。
while [ "$n" -gt 0 ]
do
percentage=${"scale=2;(100-(($n / $end) * 100))"|bc -l}}
#get url from line specified by n from file done1
nextUrls=`sed -n "${n}p" < done1`
echo -ne "${percentage}% $n / $end urls saved going to line 1. current: $nextUrls\r"
# function that gets links from the url
getlinks $nextUrls
#save n
echo $n > currentLine
let "n--"
let "end=`cat done1 |wc -l`"
done
在阅读GNU Parallel文档时,我发现该程序不支持函数,因此无法在并行处理中使用getlinks。
目前为止,我找到的最佳解决方案是:
seq 30 | parallel -n 4 --colsep ' ' echo {1} {2} {3} {4}
生成输出
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
25 26 27 28
29 30
如果我没理解错的话,上面提到的while循环应该像这样编写:
end=`cat done1 |wc -l`
seq $end -1 1 | parallel -j+4 -k
#(all exept getlinks function goes here, but idk how? )|
# everytime it finishes do
getlinks $nextUrls
thx for help in advance