我想从 python 调用一个 awk 命令行脚本:
os.system('''awk 'BEGIN{FS="\t";OFS="\n"} {a[$1]=a[$1] OFS $2 FS $3 FS $4} END{for (i in a) {print i a[i]}}' 2_lcsorted.txt > 2_locus_2.txt''')
它给出了以下错误:
awk: cmd. line:1: BEGIN{FS=" ";OFS="
awk: cmd. line:1: ^ unterminated string
awk: cmd. line:1: BEGIN{FS=" ";OFS="
awk: cmd. line:1: ^ syntax error
256
当我使用 subprocess.call 使用子进程时,会弹出另一种错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
它在 shell 中运行良好,我要做的就是将所有步骤组合在一个 python 脚本中,并且由于某些明显的原因,awk 对于某些处理步骤更好。有人可以解释一下这些错误的原因吗?