0
在Python脚本中,我试图计算{H9,H10 ... C21,H11}出现在一组文件中的次数。我不需要计算集合中的每个单个短语,只需要一个总和。文件名包含在名为“legend”的数组中,并按名称进行数字排序。 我最好的尝试是下面:Python:将egrep输出附加到文件中
for nitem in sorted(legend, key=numericalSort):
with open(nitem, 'a+') as f:
with open('block.txt', 'a+') as myfile:
var5 = 'egrep -c "H9|H10|N71|N61|H32|C81|N91|C51|C61|C41|N11|N31|C21|H11" <%s> %s' %(nitem,myfile)
os.system(var5)
当我跑,我得到了载于传说每个文件下列错误(包括下面只有一个错误消息):
sh: -c: line 0: syntax error near unexpected token `<'
sh: -c: line 0: `egrep -c "H9|H10|N71|N61|H32|C81|N91|C51|C61|C41|N11|N31|C21|H11" <file00.dat> <open file 'block.txt', mode 'a+' at 0x7f71196ec660>'
我要的是在Python中附加egrep,但不能这样做。