# Search for lines that start with From and have an at sign import re hand = open('mbox-short.txt') for line in hand: line = line.rstrip() if re.search('^X\S*: [0-9.]+', line) : print line