【问题标题】:gnu parallel input from a tsv来自 tsv 的 gnu 并行输入
【发布时间】:2013-10-17 20:20:12
【问题描述】:

我有 3 或 4 列的 tsv,每列都是 shell 脚本的参数。
所以我想使用 gnu 并行运行带有 tsv 值的 shell 脚本

~ parallel --colsep "\t" thescript.py --arg1 {1} --arg2 {2} --arg3 {3} --arg4 {4} :::: input.tsv

第 4 列并不总是存在,所以我想知道是否有一个聪明的方法来添加 --arg4 {4} 仅当 {4} 存在时。
python使用optparser.Optionparser,我更喜欢避免修改脚本。

【问题讨论】:

    标签: python gnu gnu-parallel


    【解决方案1】:

    当第 4 列没有值时,GNU Parallel 将 {4} 作为字符串“{4}”传递。

    你可以用 if 包裹thescript.py

    parallel --colsep "\t" 'if [ "{4}" = "\{4\}" ]; then thescript.py --arg1 {1} --arg2 {2} --arg3 {3}; else thescript.py --arg1 {1} --arg2 {2} --arg3 {3} --arg4 {4}; fi'  :::: input.tsv
    

    或者,如果您更喜欢可读性,请使用 Bash 函数:

    my_func() {
        if [ "$4" = "\{4\}" ]; then
            thescript.py --arg1 $1 --arg2 $2 --arg3 $3
        else
            thescript.py --arg1 $1 --arg2 $2 --arg3 $3 --arg4 $4
        fi
    }
    export -f my_func
    parallel --colsep "\t" my_func {1} {2} {3} {4} :::: input.tsv
    

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 2013-09-08
      • 1970-01-01
      相关资源
      最近更新 更多