柚子的collection

来源:互联网 发布:centos mod dav svn 编辑:程序博客网 时间:2024/04/29 06:56



脚本处理: 匹配输出


#!/usr/bin/env python# coding=utf-8# filename : parseFile.py# author : Chichio# running : python parseFile.py import osimport sys,getoptdef usage():    print "python parseFile.py destination_path"opts,args = getopt.getopt(sys.argv[1:],"h")dest_path = ""out_path = ""for op,value in opts:    if op == "-h":        usage()        sys.exit()    elif op == "":        usage()        sys.exit()if len(sys.argv)==2:    dest_path = sys.argv[1]f = open(dest_path)dirname = os.path.dirname(dest_path)filename = os.path.split(dest_path)[-1]fileFront = filename.split(".")[0]outFilename = fileFront + "_parse"out_path = os.path.join(dirname,outFilename)destFilePath = open(out_path,"w+")for line in f.readlines():    if line.startswith("628") or line.startswith("1428"):        destFilePath.write(line)f.close()destFilePath.close()


0 0
原创粉丝点击