import re import glob # Define the pattern to search for pattern = r'hostinger' # Define the pattern to exclude exclude_pattern = r'mail\.hostinger|webmail1|titan\.email|databases|hostinger\.com\/email|add-website' # Find all.txt files in the current directory txt_files = glob.glob('*.txt') # Open the result file in append mode with open('hostingerfull.txt', 'a', encoding='utf-8') as result_file: for file in txt_files: with open(file, 'r', encoding='utf-8', errors='ignore') as f: for num, line in enumerate(f, 1): if re.search(pattern, line) and not re.search(exclude_pattern, line, re.IGNORECASE): result_file.write(f"{line.strip()}\n")