The situation is as follows:
I have a .txt file with results of several nslookups.
I want to loop tru the file and everytime it hits the string "Non-authoritative answer:" the scripts has to print the following 8 lines from that position. If it works I shoud get all the positive results in my screen :).
First I had the following code:
#!/bin/usr/pythonfile = open('/tmp/results_nslookup.txt', 'r')
f = file.readlines()for positives in f:if 'Authoritative answers can be found from:' in positives:print positives
file.close()
But that only printed "Authoritative answers can be found from:" the times it was in the .txt.
The code what I have now:
#!/bin/usr/pythonfile = open('/tmp/results_nslookup.txt', 'r')
lines = file.readlines()i = lines.index('Non-authoritative answer:\n')for line in lines[i-0:i+9]:print line,file.close()
But when I run it, it prints the first result nicely to my screen but does not print the other positve results.
p.s. I am aware of socket.gethostbyname("foobar.baz") but first I want to solve this basic problem.
Thank you in advance!