I have a file that has a repeated number of blocks of different sizes as in below:
ID: 2
Time: 76
Op: GET
Domain: facebook.com
LPath: /common/css/common.css
Referer: http://google.com
User-Agent: Mozilla/4.0
ID: 3
Op: GET
Domain: rfi.fr
LPath: /common/css/common.css
Referer: http://yahoo.com
For each block, I want to print only the lines that start with 'Domain' and 'Referer'. This is how I approached the problem:
f = open('testconn.txt').read()
lines = ["Conn:" , "Domain:" , "Referer"]
for record in f.split('\n\n'):
for i in record:
if record in lines:
print record
It gives no error and prints nothing either. Any help is appreciated.