PHIL Sawyer
asked on
searching text files for email addresses
Hello
Want to search all txt files in a directory and return only the file names and lines in those files where a line contains an email address.
Regards
Want to search all txt files in a directory and return only the file names and lines in those files where a line contains an email address.
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER
# fill in the path of the input files here
my_path = "Z:/"
# put the local filenames of theinput files here
file_lst = ["FILE1.doc","FILE2.doc,et
sink = File.open(my_path + "A_JOINED.txt", "w")
file_lst.each do |fl|
# open the file and access each single line
File.open(my_path + fl, "r").each do |line|
if line =~/emailaddresses/i then
sink.write line
end
end
end