【发布时间】:2013-05-16 12:39:44
【问题描述】:
我需要编写一个 python 脚本,我需要在其中调用一些 awk 命令。
#!/usr/bin/python
import os, sys
input_dir = '/home/abc/data'
os.chdir(input_dir)
#wd=os.getcwd()
#print wd
os.system ("tail -n+2 ./*/*.tsv|cat|awk 'BEGIN{FS="\t"};{split($10,arr,"-")}{print arr[1]}'|sort|uniq -c")
第 8 行报错:SyntaxError: unexpected character after line continuation character
有没有办法让 awk 命令在 python 脚本中工作? 谢谢
【问题讨论】:
-
转义 \t 周围的引号?
-
为什么? sed/awk/sort/uniq 没有什么是你不能直接在 python 中做的,作为奖励,你得到了一个可以在所有平台上运行 python 移植到的解决方案!