#! /usr/bin/env python
import sys,os
FilePath = 'd:/SVNtest/'
FileName = FilePath + 'error.log'
ResultFile = FilePath + 'Fail.log'
KeyWord = 'error'
try:
fh = open(FileName,'r')
allLines = fh.readlines()
fh.close()
except IOError:
print "the file don't exist, Please double check!"
i = 0
counter = 0
NewLines = []
for oneLine in allLines:
i += 1
if oneLine.find(KeyWord) >= 0:
counter +=1
print 'Find the match line at %d,now total %d times' %(i,counter)
NewLines.append(oneLine)
fh = open(ResultFile,'a')
fh.writelines(NewLines)
fh.close()