with open('.\\input.jsonl') as f: for line in f: if line.find('{"target_words": "') >= 0: with open('.\\output.jsonl', "a") as f: f.write(line)