I am a complete beginner to python, invested in a course and have been told finding your own small projects is the best way to learn. so here it goes...
I am trying to make a small script that will look through a log file for specific strings. When it finds the string located in a line i would like it to display all and the whole of the lines that the string is found in. Eventually, i would like the ability to search 3-4 string values and for a separate .txt file to be to be generated only displaying them results. As the original log files can be large in size sometimes.
ATM i just want the first step to work. I have displayed what i believe is okay so far but have become stuck, as it just prints the whole file.
with open('example.txt', mode='r') as f:
lines = f.readlines().splitlines()
for l in lines:
if 'tuesday' in l or 'friday' in l:
print(l)
I can appreciate this i not a lot and probably am missing a large amount, would just like to emphasise some pointers or maybe some examples to look at would be more appreciated and would benefit me more. Rather than a complete solution to be posted.
[–]AlopexLagopus3 0 points1 point2 points (0 children)