import re f=open("pakcet_capture.txt") while str : str = f.readline() ip=re.findall(r"IP (.+?): Flags",str) length=re.findall(r"length (.+?)",str) print " ".join(ip+length) f.close()