python 把一个文件分割成2个指定内容的文件

#coding:utf-8
#!/usr/bin/python
import re
input=open('renow_dwload_20130804.txt','r')
output1=open('renow_dwload_20130804-01.txt','w+')
output2=open('renow_dwload_20130804-02.txt','w+')
while True:
  line=input.readline()
  if line :
      if 'np' in line and  'Offline' in line :
          m=re.split("[|/=?&]",line)
          if len(m)==20 : 
              n=m[0]+','+m[1]+','+m[3]+','+m[16]+','+m[12]+','+''+','+m[18]+','+m[19]
              output1.write(n)
      if 'android_pkg' in line :
          x=re.split("[|/=?&]",line)
          if len(x)==16 :
              r1=r'V\d\d\d_(.+\.Alpha)'
              u=re.findall(r1,x[6])
              v=u[0]
              y=x[0]+','+x[1]+','+x[3]+','+v+','+x[8]+','+x[12]+','+x[14]+','+x[15]
              output2.write(y)
          if len(x)==8 :
              if x[6].find('.apk')!=-1  :
                 r2= r'(renow.+\.(Alpha|Beta))'
                 w=re.findall(r2,x[6])
                 if len(w) >0 :
                     v=w[0]
                     z=v[0]
                     print x[0]
                     print z
                     y=x[0]+','+x[1]+','+x[3]+','+z+','+''+','+''+','+''+','+x[7]
                     output2.write(y)
                 else:
                     print "helo"
              else :
                 y=x[0]+','+x[1]+','+x[3]+','+''+','+''+','+''+','+''+','+x[7]
                 output2.write(y)   
  else :
    break
input.close()
output1.close()
output2.close()

posted @ 2013-08-23 10:04  沙漠里的小鱼  阅读(1288)  评论(0编辑  收藏  举报