import re with open(\'dio.txt\') as f: for line in f: y = re.match(\'^Value Node\', line) if y: next line = line.rstrip()