1. 程式人生 > >用python 處理丟包log的數字

用python 處理丟包log的數字

2008-03-31

先用bash指令碼排序,然後用python指令碼找出丟失的數字。當然,也可以完全在python指令碼中完成。 #!/usr/bin/python

filename:findlost.py

http://blog.csdn.net/ablo_zhou

email:[email protected]

date:2008.3.31

Find out what number is lost from a file

import os

infilename = raw_input(“in file name [rawpack]:”); outfilename = raw_input(“out file name [outfile]:”);

if infilename ==”” : infilename=”rawpack”;

if outfilename ==”” : outfilename=”outfile”;

cmd = (“sort.sh”,infilename,outfilename) os.system(‘ ‘.join(cmd))

f = open(outfilename);

i=0 pkid = 0 count = 0 while True : line = f.readline() if len(line) == 0: f.close() break

    pkid = int(line)
    if pkid>i:
            print "lost package ",i
            i+=1
            count +=1
    i+=1 print "=================================" print "total package num is",pkid,",lost package count:",count

執行結果: $ ./findlost.py in file name [rawpack]: out file name [outfile]: ./sort.sh,rawpack,outfile lost package 1707 lost package 2126 lost package 2139 lost package 2278 lost package 2280 lost package 2475 lost package 2763 lost package 3014 lost package 3072 lost package 3165 lost package 3271 ================================= total package num is 3778 ,lost package count: 11

如非註明轉載, 均為原創. 本站遵循知識共享CC協議,轉載請註明來源