Super Simple Code
import re
def extract_emails(input_file, output_file):
email_pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
emails = set() # Use a set to avoid duplicates
for line in infile:
found_emails = re.findall(email_pattern, line)
emails.update(found_emails)
for email in emails:
outfile.write(email + '\n')
print(f"Extracted {len(emails)} unique emails and saved them to {output_file}")
# Example usage
input_filename = "input.txt" # Change to your file that needs to be separated
output_filename = "emails.txt"
extract_emails(input_filename, output_filename)
Log in or sign up for Devpost to join the conversation.