文件样子:大概是43000+
请大家指导
019/01/03/10:03:00: 549766 0.50 -45 2019/01/03/10:03:00: 680769 1.00 -49 2019/01/03/10:03:01: 549766 0.50 -45 2019/01/03/10:03:01: 700398 1.50 -47 2019/01/03/10:03:01: 680769 1.00 -49 2019/01/03/10:03:02: 549766 0.50 -45 2019/01/03/10:03:02: 700398 1.50 -47 2019/01/03/10:03:02: 680769 1.00 -49 2019/01/03/10:03:03: 549766 0.50 -45 2019/01/03/10:03:03: 700398 1.50 -46 2019/01/03/10:03:04: 680769 1.00 -52 2019/01/03/10:03:04: 549766 0.50 -45 2019/01/03/10:03:04: 700398 1.50 -46 2019/01/03/10:03:05: 549766 0.50 -46 2019/01/03/10:03:05: 680769 1.00 -49 2019/01/03/10:03:05: 700398 1.50 -47 2019/01/03/10:03:06: 549766 0.50 -45 2019/01/03/10:03:06: 680769 1.00 -56 2019/01/03/10:03:06: 700398 1.50 -51 2019/01/03/10:03:07: 549766 0.50 -45 2019/01/03/10:03:07: 700398 1.50 -49 2019/01/03/10:03:08: 680769 1.00 -47 2019/01/03/10:03:08: 549766 0.50 -45 2019/01/03/10:03:09: 700398 1.50 -47 2019/01/03/10:03:09: 549766 0.50 -45 2019/01/03/10:03:09: 680769 1.00 -47 2019/01/03/10:03:10: 700398 1.50 -52 2019/01/03/10:03:10: 549766 0.50 -45 2019/01/03/10:03:10: 680769 1.00 -47 2019/01/03/10:03:11: 700398 1.50 -48 2019/01/03/10:03:11: 549766 0.50 -45 2019/01/03/10:03:12: 680769 1.00 -49 2019/01/03/10:03:12: 549766 0.50 -45 2019/01/03/10:03:12: 700398 1.50 -47 2019/01/03/10:03:13: 549766 0.50 -55 2019/01/03/10:03:13: 680769 1.00 -56 2019/01/03/10:03:13: 700398 1.50 -47 2019/01/03/10:03:14: 549766 0.50 -45 2019/01/03/10:03:14: 700398 1.50 -48 2019/01/03/10:03:14: 680769 1.00 -47 2019/01/03/10:03:15: 549766 0.50 -45 2019/01/03/10:03:15: 700398 1.50 -50 2019/01/03/10:03:16: 680769 1.00 -59 2019/01/03/10:03:16: 549766 0.50 -45 2019/01/03/10:03:16: 700398 1.50 -47 2019/01/03/10:03:17: 549766 0.50 -45 2019/01/03/10:03:17: 680769 1.00 -54 2019/01/03/10:03:17: 700398 1.50 -49 2019/01/03/10:03:18: 549766 0.50 -59 2019/01/03/10:03:18: 680769 1.00 -47 2019/01/03/10:03:19: 700398 1.50 -50 2019/01/03/10:03:19: 549766 0.50 -45 2019/01/03/10:03:20: 680769 1.00 -47 2019/01/03/10:03:20: 700398 1.50 -47 2019/01/03/10:03:20: 549766 0.50 -45 2019/01/03/10:03:21: 700398 1.50 -48 2019/01/03/10:03:21: 680769 1.00 -61 2019/01/03/10:03:21: 549766 0.50 -45 2019/01/03/10:03:22: 700398 1.50 -46 2019/01/03/10:03:22: 549766 0.50 -45 2019/01/03/10:03:22: 680769 1.00 -53 2019/01/03/10:03:23: 549766 0.50 -45 2019/01/03/10:03:24: 680769 1.00 -52 2019/01/03/10:03:24: 700398 1.50 -52 2019/01/03/10:03:25: 680769 1.00 -47 2019/01/03/10:03:25: 549766 0.50 -45 2019/01/03/10:03:25: 700398 1.50 -50 2019/01/03/10:03:26: 549766 0.50 -45 2019/01/03/10:03:26: 680769 1.00 -47 2019/01/03/10:03:26: 700398 1.50 -51 2019/01/03/10:03:27: 549766 0.50 -45 2019/01/03/10:03:28: 700398 1.50 -53 2019/01/03/10:03:28: 680769 1.00 -47 2019/01/03/10:03:28: 549766 0.50 -45 2019/01/03/10:03:29: 700398 1.50 -49 2019/01/03/10:03:29: 680769 1.00 -47 2019/01/03/10:03:29: 549766 0.50 -45 2019/01/03/10:03:30: 700398 1.50 -49 2019/01/03/10:03:30: 549766 0.50 -47 2019/01/03/10:03:30: 680769 1.00 -47 2019/01/03/10:03:31: 700398 1.50 -49 2019/01/03/10:03:31: 549766 0.50 -45 2019/01/03/10:03:32: 680769 1.00 -52 2019/01/03/10:03:32: 700398 1.50 -51 2019/01/03/10:03:32: 549766 0.50 -45 2019/01/03/10:03:33: 680769 1.00 -50 2019/01/03/10:03:33: 700398 1.50 -51 2019/01/03/10:03:33: 549766 0.50 -45 2019/01/03/10:03:34: 700398 1.50 -52 2019/01/03/10:03:34: 549766 0.50 -45 2019/01/03/10:03:34: 680769 1.00 -48 2019/01/03/10:03:35: 549766 0.50 -45 2019/01/03/10:03:35: 700398 1.50 -52 2019/01/03/10:03:36: 680769 1.00 -48 2019/01/03/10:03:36: 549766 0.50 -45 2019/01/03/10:03:37: 700398 1.50 -52 2019/01/03/10:03:37: 680769 1.00 -48 2019/01/03/10:03:37: 549766 0.50 -45 2019/01/03/10:03:38: 549766 0.50 -45 2019/01/03/10:03:39: 700398 1.50 -51 2019/01/03/10:03:39: 549766 0.50 -45 2019/01/03/10:03:40: 680769 1.00 -47 2019/01/03/10:03:40: 700398 1.50 -49 2019/01/03/10:03:40: 549766 0.50 -45 2019/01/03/10:03:41: 700398 1.50 -50 2019/01/03/10:03:41: 680769 1.00 -48 2019/01/03/10:03:41: 549766 0.50 -45 2019/01/03/10:03:42: 700398 1.50 -50 2019/01/03/10:03:42: 680769 1.00 -47 2019/01/03/10:03:43: 700398 1.50 -54 2019/01/03/10:03:43: 549766 0.50 -45 2019/01/03/10:03:44: 680769 1.00 -47 2019/01/03/10:03:44: 700398 1.50 -56 2019/01/03/10:03:44: 549766 0.50 -45 2019/01/03/10:03:45: 680769 1.00 -48 2019/01/03/10:03:45: 700398 1.50 -57 2019/01/03/10:03:45: 549766 0.50 -45 2019/01/03/10:03:46: 680769 1.00 -51 2019/01/03/10:03:47: 549766 0.50 -45 2019/01/03/10:03:47: 700398 1.50 -55 2019/01/03/10:03:48: 549766 0.50 -45 2019/01/03/10:03:48: 700398 1.50 -56 2019/01/03/10:03:48: 680769 1.00 -49 2019/01/03/10:03:49: 549766 0.50 -45 2019/01/03/10:03:49: 700398 1.50 -54 2019/01/03/10:03:49: 680769 1.00 -53 2019/01/03/10:03:50: 549766 0.50 -45 2019/01/03/10:03:50: 700398 1.50 -51 2019/01/03/10:03:50: 680769 1.00 -49 2019/01/03/10:03:51: 549766 0.50 -45 2019/01/03/10:03:52: 549766 0.50 -45 2019/01/03/10:03:52: 680769 1.00 -49 2019/01/03/10:03:52: 700398 1.50 -52 2019/01/03/10:03:53: 549766 0.50 -45 2019/01/03/10:03:53: 680769 1.00 -53 2019/01/03/10:03:53: 700398 1.50 -48 2019/01/03/10:03:54: 549766 0.50 -45 2019/01/03/10:03:54: 680769 1.00 -57 2019/01/03/10:03:54: 700398 1.50 -48 2019/01/03/10:03:55: 549766 0.50 -45 2019/01/03/10:03:56: 700398 1.50 -48 2019/01/03/10:03:56: 549766 0.50 -45 2019/01/03/10:03:56: 680769 1.00 -60 2019/01/03/10:03:57: 700398 1.50 -49 2019/01/03/10:03:57: 549766 0.50 -45 2019/01/03/10:03:58: 549766 0.50 -45 2019/01/03/10:03:58: 700398 1.50 -51
程序:
def get_list():#得到列表索引
f = open('D:\\pycharm\\code\\课堂\\三个标签从0.5米到6米的变化.log.bak','r',encoding='utf-8')
fileIndex = []
for lines in f:
if len(lines) < 4:
continue
item_1 = lines.split()
if item_1[1] in fileIndex: # 排除相同索引
continue
else:
fileIndex.append(item_1[1]) # 将索引值加入列表中
#fileIndex = list(set(fileIndex)) # 利用集合删除相同元素
f.close()
split_file(fileIndex)
#我重新再一次打开了文件,这一步可以在一个函数中完成中写用f.seek(0)就行
def split_file(fileIndex):#利用列表索引进行分割文件并保存
f1 = open('D:\\pycharm\\code\\课堂\\三个标签从0.5米到6米的变化.log.bak','r',encoding='utf-8')
for eachLine in f1:
if len(eachLine) < 4:
continue
item_1 = eachLine.split()
if item_1[1] == fileIndex[0]:
with open(fileIndex[0],'a') as f2:
f2.write(eachLine)
elif item_1[1] == fileIndex[1]:
with open(fileIndex[1],'a') as f2:
f2.write(eachLine)
else:
with open(fileIndex[2],'a') as f2:
f2.write(eachLine)
f1.close()