将awk与qsub一起使用以及报价问题 [英] Using awk with qsub and issues with quotations

查看:72
本文介绍了将awk与qsub一起使用以及报价问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个脚本,它将沿着以下几行提交一堆awk命令:

I'm trying to run a script which will submit a bunch of awk commands along the following lines:

qsub -l h_vmem=32G -l h_rt=04:00:00 "awk '{if (last != $10) close(last); print >> "/directory/working/"$10 ".txt"; last = $10}' /directory/working/working_file.txt"

在交互式会话中运行时,awk命令本身可以正常工作,问题是当与 qsub 结合使用时,它会返回以下内容:

The awk command itself works fine when run in an interactive session, the issue is that when combined with qsub it returns something along the lines of:

error opening awk '{if (last != 0) close(last); print >> '/directory/working: No such file or directory

最初,我认为这可以通过将整个awk命令放在双引号中来解决(如上所述),但这也返回了相同的错误.我对此的理解是,由于awk命令中包含多余的双引号,因此该命令不起作用.但是据我所知,我需要在命令中添加那些双引号.

Initially I thought this would be solved by putting the entire awk command in double quotation marks (as I've done above) but this also returned the same error. My understanding of this is that it isn't working because of the extra double quotation marks inside the awk command. But as far as I'm aware, I need those extra double quotation marks inside the command.

我尝试更改它,以使第一组双引号内的每个引号都只是单引号,但这是行不通的.然后,我尝试了:

I tried changing it so that every quotation inside the first set of double quotes were just single quotes, but that didn't work. I then tried:

qsub -l h_vmem=32G -l h_rt=04:00:00 "$(awk ...)"

但这似乎也不起作用(或者至少在提交之后,它没有返回错误,但实际上似乎没有提交.

But that did not seem to work either (or at least after submitting it, it didn't return an error but didn't actually seem to submit.

围绕各种报价,有没有办法解决这个/任何解决方案?

Is there any way around this/any solutions with all the various quotations?

推荐答案

使用多个级别的引用可能会引入错误,因此最好避免.

Using multiple levels of quoting is likely to introduce bugs, so is best avoided.

看来, qsub 需要脚本文件名或可执行程序,后跟参数.但是,两种情况下的语法不同.请参阅:通过在命令行上指定可执行文件直接提交作业

It appears that qsub expects either the filename of a script or an executable program followed by arguments. However, the syntax is different in the two cases. See: Submitting Job Directly by Specifying Executable on Command Line

qsub scriptfile

qsub -- program arg1 arg2 arg3 ...

因此,最简单的解决方案似乎不是嵌套引号,而是在-之前加上:

So the simplest solution seems to be not to nest quotes but to prepend --:

qsub -l h_vmem=32G -l h_rt=04:00:00 -- awk '{if (last != $10) close(last); print >> "/directory/working/"$10 ".txt"; last = $10}' /directory/working/working_file.txt

对于更长的命令行,将脚本另存为文件,可能是qsub可以找到它的更好的选择,因此您完全不必担心引用.

For longer commandlines, it may be better to save the script as a file, somewhere that qsub can find it, so you don't need to worry about quoting at all.

如果在其他情况下必须嵌套引号,则可以使用bash(v4.4 +)向您展示所需内容:

If you must nest quotes in other situations, you can get bash (v4.4+) to show you what is needed:

raw=$(cat <<'EOD'
awk '{if (last != $10) close(last); print >> "/directory/working/"$10 ".txt"; last = $10}' /directory/working/working_file.txt
EOD
)
quoted="${raw@Q}"

这篇关于将awk与qsub一起使用以及报价问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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