0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

forループでparallelを

Posted at
fx () {
  name=$1
  age=$2
 echo $name $age
}

みたいな関数を並列でやりたいと思う。どうしてもprallelで。
引数リストがタブ区切りのテキストで与えられているもしくはパイプの向こうからやってくる場合。

hoge 10
fuga 20
piyo 30

例えばとかいうnenrei.txtみたいなファイルがあった時

cat nenrei.txt | while read name age; do
  parallel --colsep '\t' fx $name $age
done

でいける。並列数を制限したい時は

cat nenrei.txt | while read name age; do
  parallel -j 3 --colsep '\t' fx $name $age
done

とかすれば良い。

cat nenrei.txt | while read name age; do
  parallel -j 3 --colsep '\t' fx $name $age
done > kekka.txt

とかすれば結果は書き込まれるが終わった順になるのでランダムに並びます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?