I have a string “[ERROR]: test_case_blebleble – FAILURE – 1 hr 47 min” get from console log jenkins
In my console log, I have a lot of message like this. so I want to check if have any string like this format FAILURE – 1 hr 47 min then go to get this message. So, in python how we can get it please help me = thanks
Advertisement
Answer
You could use in below way:
JavaScript
x
8
1
# Give the pattern that you are searching:
2
pattern = re.compile("[ERROR]: test_case_blebleble - FAILURE")
3
4
# Give name of your file
5
for line in open("yourfile.txt"):
6
for match in re.finditer(pattern, line):
7
print(line)
8
OR
JavaScript
1
7
1
with open(r"yourfile.txt") as infile:
2
for line in infile:
3
line=line.strip()
4
if "- FAILURE - 1 hr 47 min" in line:
5
print(line)
6
infile.close()
7
EDIT
JavaScript
1
10
10
1
import re
2
3
with open(r"yourfile.txt") as infile:
4
for line in infile:
5
line=line.strip()
6
z=re.match("^"[[a-zA-Z]+]:s[a-zA-Z]+_[a-zA-Z]+[0-9]+s+-sFAILUREs-s(0?[0-9]|1[0-9]|2[0-3])shrs(0?[0-9]|[1-5][0-9])smin"",line)
7
if z:
8
print(line)
9
infile.close()
10