I have a code that reads all the lines from multiple log files inside a directory using a given regex pattern:
Here is the code:
src_dict = ("/nfs/home/dex/work/xxx/xxx/logs")
pattern = re.compile ('(.*)for exports(.*)')
for passed_files in os.listdir(src_dict):
files = os.path.join(src_dict, passed_files)
strng = open(files)
for lines in strng.readlines():
if re.search(pattern, lines):
print lines
The above code gives me all the required lines from the log file with a time stamp at the end of each line.
./xx.xx.xx.v1.0_Final:2019-01-30 08:34:46.463 -0800 INFO [626] - Program Ended: xx::xx::xxx::xx for exports [... stuff ...] after 00:26:15
.....................and so on.
Now I want to fetch all the last lines that contains the timestamp i.e. 00:26:15
(it may always be something different)
and calculate the total and average time for all the timestamps collected from these log files.