Created
August 14, 2023 01:07
-
-
Save ColinDKelley/a522433d9bd6ac85ff8d863d7f381ba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orig = File.read("King Bee emails from Rachel.txt") | |
cleaned = orig | |
.force_encoding('BINARY') | |
.gsub("\xCA".force_encoding('BINARY'), '') | |
.gsub(/\r+/, '; ') | |
.gsub("\"; <", "\" <") | |
.gsub(/; */, "\n") | |
.gsub(/^"/, '') | |
.gsub("\" ", ' <') | |
.gsub(" <", ' ') | |
.gsub(/>$/, '') | |
.split("\n") | |
.map do |m| | |
friendly, _, email = m.rpartition(' ') | |
email.sub!(/^</, '') | |
username = email.partition('@').first | |
if friendly.include?(username) | |
[username, email] | |
else | |
[friendly, email] | |
end | |
end | |
File.write("King Bee emails - separate.csv", cleaned.map { |*args| args.to_csv }.join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment