简体   繁体   English

-c:第0行:意外令牌'('附近的语法错误

[英]-c: line 0: syntax error near unexpected token `('

I have a PYTHON script which accepts a input file and gives an output file. 我有一个PYTHON脚本,它接受输入文件并提供输出文件。 the input file and output file are spceified as sys.argv[1] and [2] as below: 输入文件和输出文件的名称分别为sys.argv [1]和[2],如下所示:

myscript.py input.file output.file

Unfortunately the input file needs to pre-processed to suit the requirements of the script. 不幸的是,输入文件需要进行预处理以适应脚本的要求。 I can pre-process the raw files and convert into an acceptable format. 我可以预处理原始文件并转换成可接受的格式。 The preprocessing step is as follow: 预处理步骤如下:

awk 'NR % 4 == 1 {print ">" $0 } NR % 4 == 2 {print $0}' filename.fastq > filename.fa

However, there are over 1000 such files and in a bid to save some storage space i want the script to take the pre-processed data through process substitution and i found a solution here: https://superuser.com/questions/1070265/how-to-pipe-awk-command-output-to-python-as-first-argument 但是,有1000多个这样的文件,为了节省一些存储空间,我希望脚本通过流程替换来获取预处理的数据,并且我在这里找到了解决方案: https : //superuser.com/questions/1070265/如何对管AWK-命令输出到蟒-AS-第一参数的

So the following worked perfectly fine: 因此,以下工作完全正常:

myscript.py <(awk 'NR % 4 == 1 {print ">" $0 } NR % 4 == 2 {print $0}' input.fastq) output_processed.fa

However, as i mentioned i have 1000 such files and i wrote a python script to loop over all the files and then nested the above command in os.system as follow 但是,正如我提到的,我有1000个这样的文件,并且我编写了一个python脚本来遍历所有文件,然后将上述命令嵌套在os.system中,如下所示

os.system("myscript.py <(awk 'NR % 4 == 1 {print ">" $0 } NR % 4 == 2 {print $0}' input.fastq) output_processed.fa")

However, this time when i run the script i get the following error: 但是,这一次,当我运行脚本时,出现以下错误:

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `myscript.py <(awk 'NR % 4 == 1 {print ">" $0 } NR % 4 == 2 {print $0}' input.fastq) output_processed.fa'

i could find there are many answers for the same error, but none of them worked for me. 我可以找到相同错误的很多答案,但是没有一个对我有用。 i have some of the links below which i tried: 我下面尝试了一些链接:

https://askubuntu.com/questions/348942/why-does-my-python-script-fail-with-syntax-errors https://askubuntu.com/questions/348942/why-does-my-python-script-fail-with-syntax-errors

https://askubuntu.com/questions/656425/syntax-error-near-unexpected-token?rq=1 https://askubuntu.com/questions/656425/syntax-error-near-unexpected-token?rq=1

https://askubuntu.com/questions/656425/syntax-error-near-unexpected-token https://askubuntu.com/questions/656425/syntax-error-near-unexpected-token

https://askubuntu.com/questions/372926/bash-syntax-error-near-unexpected-token https://askubuntu.com/questions/372926/bash-syntax-error-near-unexpected-token

when i used the above solution i got EOL error 当我使用上述解决方案时,出现停产错误

I came to know that "(" is a wrong syntax from here : bash: syntax error near unexpected token `(' 我从这里知道“(”是错误的语法: bash:意外标记'('附近的语法错误

then i tried with "/" and then i get the following error: 然后我尝试使用“ /”,然后出现以下错误:

 IOError: [Errno 2] No such file or directory: '/<(awk NR % 4 == 1 {print ">" $0 } NR % 4 == 2 {print $0} input.fastq)

Could you please suggest a solution for me? 您能为我提出解决方案吗?

Explicitly use bash for the process substitution 明确使用bash替代流程

os.system("bash -c \"myscript.py <(awk -v gt='>' 'NR % 4 == 1 {print gt $0 } NR % 4 == 2 {print $0}' input.fastq) output_processed.fa\"")

I brought the ">" string out of the awk body to reduce the number of levels of nested quotes. 我将">"字符串从awk主体中移出,以减少嵌套引号的数量。

or use the default /bin/sh and write the awk output to a temp file. 或使用默认的/ bin / sh并将awk输出写入临时文件。

os.system("awk 'NR % 4 == 1 {print \">\" $0 } NR % 4 == 2 {print $0}' input.fastq > temp && myscript.py temp output_processed.fa; rm -f temp")

If you control myscript.py , allow it to accept data on stdin instead of a filename, and you can write 如果您控制myscript.py ,允许它接受stdin上的数据而不是文件名,则可以编写

os.system("awk '...' input.fastq | myscript.py output_processed.fa")

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

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