Jun-18-2020, 03:31 AM
Hey all,
Hoping one of you folks might steer me in the right direction. I have a pretty big log file, and another file with a list of unique event identifiers. What I need to do is go through this big log file, and look for any line in it that contains a unique identifier from the second file. If it's found, I want to print not the line the event is on, but two lines below it ( on the log file). I'm pretty novice, so I'm sure I'm missing something obvious. Here's where I'm at so far. Any hint would be greatly appreciated. This is the culmination of many hours of fidgeting around, trying different methods found in forums. Like I said, I'm pretty novice.
Example Input + Expected Output:
f2
----------
11111
22222
33333
44444
f1
---------
asdfasldfkjas11111aervoiuer
asdlojaer;lg
aekrjnvetk22222
asldkaer
aa;lckr44444rldfvetr
expected output
----------
asdfasldfkjas11111aervoiuer
aekrjnvetk22222
aa;lckr44444rldfvetr
current output
---------------------
Hoping one of you folks might steer me in the right direction. I have a pretty big log file, and another file with a list of unique event identifiers. What I need to do is go through this big log file, and look for any line in it that contains a unique identifier from the second file. If it's found, I want to print not the line the event is on, but two lines below it ( on the log file). I'm pretty novice, so I'm sure I'm missing something obvious. Here's where I'm at so far. Any hint would be greatly appreciated. This is the culmination of many hours of fidgeting around, trying different methods found in forums. Like I said, I'm pretty novice.
with open('XXXXXXXXXXX', 'r+') as f1: with open('XXXXXXXXXXX', 'r+') as f2: writelines = f2.readlines() alines = f1.readlines() lines = iter(alines) lines2 = iter(writelines) for line in lines: for line2 in lines2: if line2 in line: print(line) breakYou can see at this point I'm not even trying to get two lines below the event ID, just trying to pull the event ID line as a starting point. Eventually I need to tackle the next() function, which I'm pretty iffy on.
Example Input + Expected Output:
f2
----------
11111
22222
33333
44444
f1
---------
asdfasldfkjas11111aervoiuer
asdlojaer;lg
aekrjnvetk22222
asldkaer
aa;lckr44444rldfvetr
expected output
----------
asdfasldfkjas11111aervoiuer
aekrjnvetk22222
aa;lckr44444rldfvetr
current output
---------------------