Hi All,
I am facing one problem with my code when reading a file. The file is a log file.
Below is the log file. Basely I wish to find the string, my string order:
Step 1 find this string : m>>> DL- ingress traffic
Step 2 find this string: >>> DL- Mcs= 26.0 m
then find >>> DL- ingress traffic
sometimes the log file will be incomplete, as you see below DL-MCS come first, this is an incomplete log. Is there any method to skip the beginning file.
It’s pretty hard to explain, let look at below log, and my code
log file:
[20230310.232915.783022][info]:[DL- UE[28]: Tput= 14.699137 Mbps, Mcs= 26.0(Sigma= 0.0)]
[20230310.232915.783051][info]:[DL- UE[29]: Tput= 14.699133 Mbps, Mcs= 26.0(Sigma= 0.0)]
[20230310.232915.783061][info]:[>>> DL- Mcs= 26.0, RbNum= 99.0, Layers= 4.0]
[20230311.012825.882186][info]:[e[40;32m>>> DL- ingress traffic: 117.590118(Mbps), egress traffic: 120.919250(Mbps), ReTx: 2.519794(Mbps)e[0m]
[20230311.012825.882339][info]:[>>> DL- Mcs= 26.0, RbNum= 71.2, Layers= 4.0]
[20230311.012825.882189][info]:[e[40;32m>>> DL- ingress traffic: 119.000(Mbps), egress traffic: 125.919250(Mbps), ReTx: 2.819794(Mbps)e[0m]
[20230311.012835.882479][info]:[>>> DL- Mcs= 26.0, RbNum= 70.7, Layers= 4.0]
My code:
import re
elogfileName="elog2.txt"
with open(elogfileName, 'r') as filedata:
for line in filedata:
#print(re.findall(r"(m>>>\ DL\- ?)", line))
if re.findall(r"(m>>>\ DL\- ?)", line):
print(line.strip())
if re.search(r'\[(\d+\.\d+\.\d+)\].*?(>>> DL- Mcs=[^]]+)', line):
print(line.strip())
Please refer to the picture, I have labeled A BC
A is an incomplete log, which I wish to skip
B I want to start searching from here ([>>> DL- Mcs)
C after finding B will find C (2m>>> DL- )
Is there any ways to ignore A part, the A string should be after B, but due to this is an incomplete log.
I can manually remove the log of A, but is there any better way to establish using the code?