简体   繁体   English

单引号内的单引号-Bash命令行GNU parallel

[英]Single quotes within single quotes issue - Bash command line GNU parallel

I am new to Bash command line use, and need to know the correct syntax for doing single quotes within existing single quotes. 我是Bash命令行使用的新手,并且需要知道在现有单引号内执行单引号的正确语法。

ls *file.fa | parallel -j4 'perl -pe 's/^>/>{}/' {} >newfile_{}'

I know the GNU parallel command is not particularly well known or used but i don't think the syntax would be different for a different command that requires single quotes within single quotes. 我知道GNU并行命令并不是特别为人所知或使用,但我认为对于需要在单引号内使用单引号的不同命令,语法不会有所不同。 The command is to change > to >file.fa (> then the file name) within the file called file.fa, where {} incorporates the file piped from the ls *file.fa section. 命令是在名为file.fa的文件中将>更改为> file.fa(>然后是文件名),其中{}合并了从ls * file.fa节中管道传输的文件。

Any help is much appreciated 任何帮助深表感谢

Quoting in GNU Parallel is a black art. 用GNU Parallel报价是一门妖术。 There is a whole section dedicated to it in the manual: http://www.gnu.org/software/parallel/man.html#QUOTING 手册中有专门针对整个章节的内容: http : //www.gnu.org/software/parallel/man.html#QUOTING

Conclusion: To avoid dealing with the quoting problems it may be easier just to write a small script or a function (remember to export -f the function) and have GNU parallel call that. 结论:为了避免处理引用问题,仅编写一个小的脚本或函数(记住要导出-f函数)并让GNU 并行调用它可能会更容易。

In this case I would write a function: 在这种情况下,我将编写一个函数:

fasta_namer() {
  NAME=$1
  perl -pe "s/^>/>$NAME/" "$NAME" >newfile_"$NAME"
}
export -t fasta_namer
ls *file.fa | parallel -j4 fasta_namer {}

FASTA file names are usually not weird, but if they are (eg containing ' " \\ * & / or other crazy chars) then this might solve it: FASTA文件名通常并不奇怪,但是如果它们很奇怪(例如,包含'“ \\ *&/或其他疯狂的字符),则可以解决该问题:

fasta_namer() {
  NAME=$1
  PERLQUOTED=$2
  NEWNAME=$3
  perl -pe "s/^>/>$PERLQUOTED/" "$NAME" >"$NEWNAME"
}
export -t fasta_namer
ls *file.fa | parallel -j4 fasta_namer {} '{=$_=quotemeta($_)=}' {.}.new.fa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM