标签:
#!/usr/bin
#coding:utf-8
import os, re, errno
ls = os.popen(‘ls *.log‘).readlines()
dirs = []
lines = []
for line in ls:
if line.strip():
dirs.append(re.split(‘-|\.‘, line.strip())[-2])
lines.append(line.strip())
for dir in list(set(dirs)):
# the actual code
try:
os.makedirs(dir)
print ‘create dir success: ‘+dir
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(dir):
pass
flag = dir.replace(‘_‘, ‘-‘) + ‘T‘
for l in [line for line in lines if line.endswith(dir+‘.log‘)]:
cmd = ‘csplit ‘+ l +‘ -f ‘+l+‘_ /‘+ flag +‘[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\+08:00\ \]\ [0-9]/ {*}‘
os.system(cmd)
标签:
原文地址:http://www.cnblogs.com/martinjinyu/p/4326027.html