import re import sys inFile = sys.argv[1] outFile = sys.argv[2] with open(inFile, 'r', encoding="utf-8") as sampleCheck, open(outFile, 'w', encoding='utf-8') as outputFile: pattern = re.compile(r'19[0-9][0-9] r\.') for line in sampleCheck: match = re.search(pattern, line) if match: outputFile.write(line) print(line, end='')