python
import time
import re
def date_time_float(time_str, time_format=None):
time_stamp = 0
if len(time_str) > 24:
time_str = time_str[:24]
try:
if time_format is None:
time_format = '%Y-%m-%d %H:%M:%S'
if 'T' in time_str:
time_format = '%Y-%m-%dT%H:%M:%SZ'
ms_float_time = 0
s_time = time_str.split('.')[0]
if '.' in time_str:
ms_float_time = float(time_str.split('.')[-1]) / 1000.0
time_stamp = time.mktime(time.strptime(s_time, time_format)) + ms_float_time
except:
pass
return time_stamp
temp_str = '''2024-07-17 17:51:16.790 <142> [2024-7-17 17:51:23.91844][PID2615][ffffffff][L2S][info]L2S_RrcProcPhyFraNumInfo: 876:[0,1207,17908] PhyFraNum:0 next pos
2024-07-17 17:51:17.212 <134> [2024-7-17 17:51:23.522884][PID2652][ffffffff][OM][info]FPGAM_Task:1772:[0,1207,18339] FPGAM Module resaved message!
2024-07-17 17:51:18.366 <142> [2024-7-17 17:51:24.671879][PID2615][ffffffff][NAS][info]nas_timer_stop: 301:[0,1207,19488] MM-PROC - Stop timer id (998638)
2024-07-17 17:51:19.219 <134> [2024-7-17 17:51:25.208775][PID2641][10000016][MSGTRACE][info]PFM_MsgTask:1867:[0,1207,20025] TASK_OAM_PFM Received message 0x1000
2024-07-17 17:51:20.383 <142> [2024-7-17 17:51:26.691849][PID2615][ffffffff][NAS][info]nas_timer_stop: 301:[0,1207,21508] MM-PROC - Stop timer id (1118223)
2024-07-17 17:51:21.397 <139> [2024-7-17 17:51:27.701906][PID2615][0][MOS][error]MOS_TimerDelete: 496:[0,1207,22518] TIMER ID 1194679 ERROR! not match 0
2024-07-17 17:51:22.406 <139> [2024-7-17 17:51:28.711897][PID2615][0][MOS][error]MOS_TimerDelete: 496:[0,1207,23528] TIMER ID 1300996 ERROR! not match 0
2024-07-17 17:51:27.642 <142> [2024-7-17 17:51:28.712523][PID2615][ffffffff][NAS][info]nas_timer_start: 268:[0,1207,23529] create nas timer (1373732)'''
ori_list = temp_str.split('\n')
start_time = '2024-07-17 17:51:21.397'
start_time_stamp = date_time_float(start_time)
dst_list = []
for line in ori_list:
pattn = re.compile('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3})')
crt_line_time = re.findall(pattn, line)
if crt_line_time:
time_stamp = date_time_float(crt_line_time[0])
if start_time_stamp <= time_stamp:
print(line)
运行结果: