Skip to content

Instantly share code, notes, and snippets.

@ColinDKelley
Created August 14, 2023 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColinDKelley/a522433d9bd6ac85ff8d863d7f381ba9 to your computer and use it in GitHub Desktop.
Save ColinDKelley/a522433d9bd6ac85ff8d863d7f381ba9 to your computer and use it in GitHub Desktop.
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