Hello i have a large text file containing multiple information. I'd like to extract only e-mail id and phone numbers with a python program or a tool.
CodePudding user response:
Without the schema or a sample of the file you're working with, it is impossible to help you. The fact that you haven't provided a sample implies that you're fairly new to this, furthermore there's a wide range of answers about it here on Stack Overflow (how to parse files), or are ease enough to find via googling. But generally you go line by line in the file and extract the information you need. To do the extraction you need either regex
or you use the trim()
method to sanitize whitespace and the split()
method to split the line on certain characters.
If you want a better answer provide at least one line of the text file with fake email/phone number.
CodePudding user response:
empty_list=[]
with open('test.txt', 'rt') as reading:
for line in reading:
cleaned = line.rstrip('\n') # assume each field to be in new line, strip whitespace
empty_list.append(cleaned)
print(empty_list)