Aug-22-2022, 02:24 AM
import io import re data = io.StringIO(""" This is not the first line 2022-08-14 14:37:46.523,17784 ,Information,"==================== Bac Start Run ====================" 2022-08-14 14:37:46.523,17784 ,Information,"Bac Info: [DS_DK] Bac Test Result : Passed [DS_DK] Bac Iteration Result : Passed 2022-08-14 14:37:46.524,17784 ,Warning Condition: NO Condition Allowed Stages: Any Stage Set Type: Hard 2022-08-14 14:39:00.032,15060 ,Information, Available network interfaces : [Bac Setup] Ethernet Connection -2 [Bac Setup] USB 3.0 to GB Ethernet """) date_pattern = re.compile("^\d{4}-\d{2}-\d{2}") first = last = None for line in data: if re.search(date_pattern, line): last = line if first is None: first = line print(first) print(last)
Output:2022-08-14 14:37:46.523,17784 ,Information,"==================== Bac Start Run ===================="
2022-08-14 14:39:00.032,15060 ,Information, Available network interfaces :