hey thanks, one more question though. How do i tell it to keep doing this until the end of the file? Im going to make a while loop, but what would i put for the loop.
I just want to make sure i understand these correct. Does it take the first line and process it, then go back to the beginning and process line two and then go back and so on and so on? Or does it do it for all the lines at the same time?
Well, either of the two commands I gave will will work on the entire file. I don't see any reason why you'd need a loop just to print your chosen field.
02/10/2006 [08:00:02] report from System
IWF problem , critical, 20 minutes
problem : Server down
02/10/2006 [08:05:12] report from system
Node down, minor, 5 minutes
problem : link down
02/10/2006 [20:15:04] report from system
IWF problem, major, 30 minutes
problem : System reload
02/10/2006 [23:00:42] report from system
IWF problem, critical , 5 minutes
problem : Server down
.........
I just want get all IWF problem from this file, but contain date, and problem reason and make 1 file that name "IWFPROBLEM" for example in this file just contain
....
02/10/2006 [20:15:04] report from system
IWF problem, major, 30 minutes
problem : System reload
02/10/2006 [23:00:42] report from system
IWF problem, critical , 5 minutes
problem : Server down
....
#!/usr/bin/python
data = open("report.log").readlines()
o = open("IWFPROBLEM","a") #open file for appending
for i in range(len(data)):
if "IWF problem" in data:
print >>o, ''.join(data[i-1:i+2])
output:
02/10/2006 [08:00:02] report from System
IWF problem , critical, 20 minutes
problem : Server down
02/10/2006 [20:15:04] report from system
IWF problem, major, 30 minutes
problem : System reload
02/10/2006 [23:00:42] report from system
IWF problem, critical , 5 minutes
problem : Server down