GNU并行内的Perl命令? [英] Perl command inside GNU parallel?

查看:51
本文介绍了GNU并行内的Perl命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试并行运行:

parallel perl -pe '!/^step/ && s/(\S+)/sprintf("%.2e", $1)/ge' {} > {}.fix ::: *

也就是说,我想对当前目录中的所有文件并行执行 perl 命令.这不起作用,但我不知道为什么.

That is, I want to execute the perl command on all files in the current directory, in parallel. This is not working, but I have no idea why.

注释:perl 命令正在修复表中的浮点数.请参阅替换现有文件中浮点数的精度.

Comment: The perl command is fixing floating-point numbers in tables. See Replacing precision of floating point numbers in existing file.

推荐答案

在 Bash 中你可以创建一个函数:

In Bash you can make a function:

doit() {
  perl -pe '!/^step/ && s/(\S+)/sprintf("%.2e", $1)/ge' "$1" > "$2"
}
export -f doit
parallel doit {} {}.fix ::: *

在 Zsh 中导出函数需要使用变量:

Exporting functions in Zsh requires using a variable:

doit() {
  perl -pe '!/^step/ && s/(\S+)/sprintf("%.2e", $1)/ge' "$1" > "$2"
}
PARALLEL_ENV="$(typeset -f doit)"
parallel doit {} {}.fix ::: *

或者,您可以引用 perl 表达式和重定向(这也适用于 Bash):

Alternatively you can quote the perl expression and the redirection (which will also work in Bash):

parallel perl -pe \''!/^step/ && s/(\S+)/sprintf("%.2e", $1)/ge'\' {} '>' {}.fix ::: *

这篇关于GNU并行内的Perl命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆