June 2017
Intermediate to advanced
446 pages
10h 10m
English
For our first search, we will simply use the regular expression module to look for the terms we are looking for. We will use a simple loop to the following:
#!/usr/bin/env python3import re, datetimestartTime = datetime.datetime.now()with open('sample_log_anonymized.log', 'r') as f: for line in f.readlines(): if re.search('ACLLOG-5-ACLLOG_FLOW_INTERVAL', line): print(line)endTime = datetime.datetime.now()elapsedTime = endTime - startTimeprint("Time Elapsed: " + str(elapsedTime))
The result is about 6/100th of a second to search through the log file:
$ python3 python_re_search_1.py2014 Jun 29 19:21:18 Nexus-7000 %ACLLOG-5-ACLLOG_FLOW_INTERVAL: Src IP: 10.1 0.10.1,2014 Jun 29 19:26:18 Nexus-7000 %ACLLOG-5-ACLLOG_FLOW_INTERVAL: ...
Read now
Unlock full access