Skip to content

Instantly share code, notes, and snippets.

@mdPlusPlus
Created May 12, 2019 19:17
Show Gist options
  • Save mdPlusPlus/8b293ee582aa01231406d7f98f8982ac to your computer and use it in GitHub Desktop.
Save mdPlusPlus/8b293ee582aa01231406d7f98f8982ac to your computer and use it in GitHub Desktop.
# 1. Put items in brackets on new lines "xxx (abc@gmail.com" -> "xxx \nabc@gmail.com"
# 2. Get only email addresses (contains "@")
# 3. Get rid of placeholders ("*")
# 4. Remove all spaces
# 5. Convert uppercase to lowercase
# 6. Sort and remove duplicates
sanitized_input=$(sed -e 's/(/\n/g' -e 's/)//g' "$1" | grep -F '@' | grep -F -v '*' | sed 's/ //g' | tr '[:upper:]' '[:lower:]' | sort -u)
# Get all Google accounts (without the @domain part)
google_accs=$(echo "${sanitized_input}" | grep -F -i -e '@gmail.com' -e '@googlemail.com' | sed -e 's/@googlemail.com//g' -e 's/@gmail.com//g' | sort -u)
# Add @gmail.com and @googlemail.com
gmail=$(echo "${google_accs}" | sed -e 's/$/@gmail.com/')
googlemail=$(echo "${google_accs}" | sed -e 's/$/@googlemail.com/')
# Add modified Google accounts back to the input (echo weirdness because of newlines between the variables)
sanitized_input=$(echo "${sanitized_input}" && echo "${gmail}" && echo "${googlemail}")
# Sort again
sanitized_input=$(echo "${sanitized_input}" | sort -u)
echo "${sanitized_input}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment