擅长:python、mysql、java
<p>这基本上可以做到:</p>
<pre><code>def stat_entry(line):
return line.startswith('STATISTICS')
def date_entry(line):
return line.startswith('20')
def findIcommingStats():
date = ''
with open("result.log", "r") as replication_file:
with open("incomingTemp.txt", "w") as tempFile:
for line in replication_file:
if date_entry(line):
date = ' '.join(line.split(' ')[:2]) # set new date
elif stat_entry(line):
tempFile.write(date + ' ' + line) # write to tempfile
findIcommingStats()
</code></pre>
<p>输出:</p>
<pre><code>2015/07/08 10:14:46.971 STATISTICS: name=gridDeltaMarkerIncomingData...
2015/07/08 10:14:46.971 STATISTICS: name=gridDeltaMarkerIncomingData...
2015/07/08 10:14:46.971 STATISTICS: name=gridDeltaMarkerIncomingData...
</code></pre>
<p>如您所见,我分解了<code>stat_entry</code>和<code>date_entry</code>函数;您可能希望更改这些函数,并添加一些更好的条件来检查给定的行是日期还是统计条目。你知道吗</p>