import sys import re 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'(\bp\w*ies\b)', re.IGNORECASE) for line in sampleCheck: match = re.search(pattern, line) if match: outputFile.write(line) print(line, end='')