How to rename many old email addresses to new domain, when merging companies.

  1. Extract the current contacts from active directory into a csv file. (in this example the file is named 50-contacts.csv)

  2. Identify the email address column. (in this example it is email)

  3. We are using libraries - dplyr, and stringr

  4. We will create a new data frame named “AD”

library("stringr")
library("dplyr")
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
  1. Our code below will read the 50-contacts.csv file and put it into the AD data frame. and display results.
AD <-read.csv('C:/Users/FMOF/Downloads/test/50-contacts.csv')
AD
##    first_name last_name               address            city state   zip        phone                            email
## 1       James      Butt    6649 N Blue Gum St     New Orleans    LA 70116 504-845-1427             jbutt@old-domain.com
## 2   Josephine   Darakjy   4 B Blue Ridge Blvd        Brighton    MI 48116 810-374-9840 josephine_darakjy@old-domain.com
## 3         Art microsoft  8 W Cerritos Ave #54      Bridgeport    NJ  8014 856-264-4130               art@old-domain.com
## 4       Lenna  Paprocki           639 Main St       Anchorage    AK 99501 907-921-2010         lpaprocki@old-domain.com
## 5     Donette    Foller          34 Center St        Hamilton    OH 45011 513-549-4561    donette.foller@old-domain.com
## 6      Simona microsoft          3 Mcauley Dr         Ashland    OH 44805 419-800-6759            simona@old-domain.com
## 7      Mitsue   Tollner             7 Eads St         Chicago    IL 60632 773-924-8565    mitsue_tollner@old-domain.com
## 8       Leota  Dilliard      7 W Jackson Blvd        San Jose    CA 95111 408-813-1105             leota@old-domain.com
## 9        Sage    Wieser      5 Boston Ave #88     Sioux Falls    SD 57105 605-794-4895       sage_wieser@old-domain.com
## 10       Kris   Marrier 228 Runamuck Pl #2808       Baltimore    MD 21224 410-804-4694              kris@old-domain.com
## 11      Minna    Amigon      2371 Jerrold Ave      Kulpsville    PA 19443 215-422-8694      minna_amigon@old-domain.com
## 12       Abel   Maclead    37275 St  Rt 17m M   Middle Island    NY 11953 631-677-3675          amaclead@old-domain.com
## 13      Kiley Caldarera      25 E 75th St #69     Los Angeles    CA 90034 310-254-3084   kiley.caldarera@old-domain.com
## 14   Graciela      Ruta 98 Connecticut Ave Nw   Chagrin Falls    OH 44023 440-579-7763             gruta@old-domain.com
## 15      Cammy   Albares      56 E Morehead St          Laredo    TX 78045 956-841-7216          calbares@old-domain.com
## 16     Mattie  Poquette   73 State Road 434 E         Phoenix    AZ 85013 602-953-6360            mattie@old-domain.com
## 17    Meaghan    Garufi   69734 E Carrillo St    Mc Minnville    TN 37110 931-235-7959           meaghan@old-domain.com
## 18     Gladys       Rim  322 New Horizon Blvd       Milwaukee    WI 53207 414-377-2880        gladys.rim@old-domain.com
## 19       Yuki   Whobrey      1 State Route 27          Taylor    MI 48180 313-341-4470      yuki_whobrey@old-domain.com
## 20   Fletcher     Flosi   394 Manchester Blvd        Rockford    IL 61109 815-426-5657    fletcher.flosi@old-domain.com
## 21      Bette     Nicka           6 S 33rd St           Aston    PA 19014 610-492-4643       bette_nicka@old-domain.com
## 22   Veronika    Inouye       6 Greenleaf Ave        San Jose    CA 95111 408-813-4592           vinouye@old-domain.com
## 23    Willard   Kolmetz      618 W Yakima Ave          Irving    TX 75062 972-896-4882           willard@old-domain.com
## 24    Maryann microsoft      74 S Westgate St          Albany    NY 12204 518-448-8982        mmicrosoft@old-domain.com
## 25     Alisha microsoft         3273 State St       Middlesex    NJ  8846 732-635-3453            alisha@old-domain.com
## 26     Allene  Iturbide         1 Central Ave   Stevens Point    WI 54481 715-530-9863   allene_iturbide@old-domain.com
## 27     Chanel     Caudy   86 Nw 66th St #8673         Shawnee    KS 66218 913-899-1103      chanel.caudy@old-domain.com
## 28    Ezekiel      Chui       2 Cedar Ave #84          Easton    MD 21601 410-235-8738           ezekiel@old-domain.com
## 29     Willow     Kusko    90991 Thorburn Ave        New York    NY 10011 212-934-5167            wkusko@old-domain.com
## 30   Bernardo   Figeroa         386 9th Ave N          Conroe    TX 77301 936-597-3614          bfigeroa@old-domain.com
## 31      Ammie    Corrio    74874 Atlantic Ave        Columbus    OH 43215 614-648-3265             ammie@old-domain.com
## 32   Francine   Vocelka          366 South Dr      Las Cruces    NM 88011 505-335-5293  francine_vocelka@old-domain.com
## 33      Ernie  Stenseth       45 E Liberty St Ridgefield Park    NJ  7660 201-387-9093    ernie_stenseth@old-domain.com
## 34     Albina     Glick            4 Ralph Ct        Dunellen    NJ  8812 732-782-6701            albina@old-domain.com
## 35    Alishia     Sergi 2742 Distribution Way        New York    NY 10025 212-753-2740            asergi@old-domain.com
## 36    Solange    Shinko           426 Wolf St        Metairie    LA 70002 504-265-8174           solange@old-domain.com
## 37       Jose  Stockham       128 Bransten Rd        New York    NY 10011 212-569-4233              jose@old-domain.com
## 38    Rozella  Ostrosky        17 Morena Blvd       Camarillo    CA 93012 805-609-1531  rozella.ostrosky@old-domain.com
## 39  Valentine   Gillian         775 W 17th St     San Antonio    TX 78204 210-300-6244 valentine_gillian@old-domain.com
## 40       Kati Rulapaugh       6980 Dorsett Rd         Abilene    KS 67410 785-219-7724    kati.rulapaugh@old-domain.com
## 41   Youlanda  Schemmer         2881 Lewis Rd      Prineville    OR 97754 541-993-2611          youlanda@old-domain.com
## 42       Dyan   Oldroyd     7219 Woodfield Rd   Overland Park    KS 66204 913-645-8918          doldroyd@old-domain.com
## 43     Roxane   Campain          1048 Main St       Fairbanks    AK 99708 907-335-6568            roxane@old-domain.com
## 44     Lavera     Perin           678 3rd Ave           Miami    FL 33196 305-995-2078            lperin@old-domain.com
## 45      Erick   Ferencz       20 S Babcock St       Fairbanks    AK 99712 907-227-6777     erick.ferencz@old-domain.com
## 46     Fatima   Saylors      2 Lighthouse Ave         Hopkins    MN 55343 952-479-2375          fsaylors@old-domain.com
## 47       Jina  Briddick       38938 Park Blvd          Boston    MA  2128 617-997-5771     jina_briddick@old-domain.com
## 48    Kanisha   Waycott         5 Tomahawk Dr     Los Angeles    CA 90006 323-315-7314   kanisha_waycott@old-domain.com
## 49    Emerson    Bowley         762 S Main St         Madison    WI 53711 608-658-7940    emerson.bowley@old-domain.com
## 50      Blair     Malet         209 Decker Dr    Philadelphia    PA 19132 215-794-4519            bmalet@old-domain.com
  1. This is the actual code that does the work. We are looking at the AD data frame in the email column replacing old-domain with newcompany from anything in that column.
AD$email <- str_replace(AD$email, "old-domain.com", "newcompany.com")
AD
##    first_name last_name               address            city state   zip        phone                            email
## 1       James      Butt    6649 N Blue Gum St     New Orleans    LA 70116 504-845-1427             jbutt@newcompany.com
## 2   Josephine   Darakjy   4 B Blue Ridge Blvd        Brighton    MI 48116 810-374-9840 josephine_darakjy@newcompany.com
## 3         Art microsoft  8 W Cerritos Ave #54      Bridgeport    NJ  8014 856-264-4130               art@newcompany.com
## 4       Lenna  Paprocki           639 Main St       Anchorage    AK 99501 907-921-2010         lpaprocki@newcompany.com
## 5     Donette    Foller          34 Center St        Hamilton    OH 45011 513-549-4561    donette.foller@newcompany.com
## 6      Simona microsoft          3 Mcauley Dr         Ashland    OH 44805 419-800-6759            simona@newcompany.com
## 7      Mitsue   Tollner             7 Eads St         Chicago    IL 60632 773-924-8565    mitsue_tollner@newcompany.com
## 8       Leota  Dilliard      7 W Jackson Blvd        San Jose    CA 95111 408-813-1105             leota@newcompany.com
## 9        Sage    Wieser      5 Boston Ave #88     Sioux Falls    SD 57105 605-794-4895       sage_wieser@newcompany.com
## 10       Kris   Marrier 228 Runamuck Pl #2808       Baltimore    MD 21224 410-804-4694              kris@newcompany.com
## 11      Minna    Amigon      2371 Jerrold Ave      Kulpsville    PA 19443 215-422-8694      minna_amigon@newcompany.com
## 12       Abel   Maclead    37275 St  Rt 17m M   Middle Island    NY 11953 631-677-3675          amaclead@newcompany.com
## 13      Kiley Caldarera      25 E 75th St #69     Los Angeles    CA 90034 310-254-3084   kiley.caldarera@newcompany.com
## 14   Graciela      Ruta 98 Connecticut Ave Nw   Chagrin Falls    OH 44023 440-579-7763             gruta@newcompany.com
## 15      Cammy   Albares      56 E Morehead St          Laredo    TX 78045 956-841-7216          calbares@newcompany.com
## 16     Mattie  Poquette   73 State Road 434 E         Phoenix    AZ 85013 602-953-6360            mattie@newcompany.com
## 17    Meaghan    Garufi   69734 E Carrillo St    Mc Minnville    TN 37110 931-235-7959           meaghan@newcompany.com
## 18     Gladys       Rim  322 New Horizon Blvd       Milwaukee    WI 53207 414-377-2880        gladys.rim@newcompany.com
## 19       Yuki   Whobrey      1 State Route 27          Taylor    MI 48180 313-341-4470      yuki_whobrey@newcompany.com
## 20   Fletcher     Flosi   394 Manchester Blvd        Rockford    IL 61109 815-426-5657    fletcher.flosi@newcompany.com
## 21      Bette     Nicka           6 S 33rd St           Aston    PA 19014 610-492-4643       bette_nicka@newcompany.com
## 22   Veronika    Inouye       6 Greenleaf Ave        San Jose    CA 95111 408-813-4592           vinouye@newcompany.com
## 23    Willard   Kolmetz      618 W Yakima Ave          Irving    TX 75062 972-896-4882           willard@newcompany.com
## 24    Maryann microsoft      74 S Westgate St          Albany    NY 12204 518-448-8982        mmicrosoft@newcompany.com
## 25     Alisha microsoft         3273 State St       Middlesex    NJ  8846 732-635-3453            alisha@newcompany.com
## 26     Allene  Iturbide         1 Central Ave   Stevens Point    WI 54481 715-530-9863   allene_iturbide@newcompany.com
## 27     Chanel     Caudy   86 Nw 66th St #8673         Shawnee    KS 66218 913-899-1103      chanel.caudy@newcompany.com
## 28    Ezekiel      Chui       2 Cedar Ave #84          Easton    MD 21601 410-235-8738           ezekiel@newcompany.com
## 29     Willow     Kusko    90991 Thorburn Ave        New York    NY 10011 212-934-5167            wkusko@newcompany.com
## 30   Bernardo   Figeroa         386 9th Ave N          Conroe    TX 77301 936-597-3614          bfigeroa@newcompany.com
## 31      Ammie    Corrio    74874 Atlantic Ave        Columbus    OH 43215 614-648-3265             ammie@newcompany.com
## 32   Francine   Vocelka          366 South Dr      Las Cruces    NM 88011 505-335-5293  francine_vocelka@newcompany.com
## 33      Ernie  Stenseth       45 E Liberty St Ridgefield Park    NJ  7660 201-387-9093    ernie_stenseth@newcompany.com
## 34     Albina     Glick            4 Ralph Ct        Dunellen    NJ  8812 732-782-6701            albina@newcompany.com
## 35    Alishia     Sergi 2742 Distribution Way        New York    NY 10025 212-753-2740            asergi@newcompany.com
## 36    Solange    Shinko           426 Wolf St        Metairie    LA 70002 504-265-8174           solange@newcompany.com
## 37       Jose  Stockham       128 Bransten Rd        New York    NY 10011 212-569-4233              jose@newcompany.com
## 38    Rozella  Ostrosky        17 Morena Blvd       Camarillo    CA 93012 805-609-1531  rozella.ostrosky@newcompany.com
## 39  Valentine   Gillian         775 W 17th St     San Antonio    TX 78204 210-300-6244 valentine_gillian@newcompany.com
## 40       Kati Rulapaugh       6980 Dorsett Rd         Abilene    KS 67410 785-219-7724    kati.rulapaugh@newcompany.com
## 41   Youlanda  Schemmer         2881 Lewis Rd      Prineville    OR 97754 541-993-2611          youlanda@newcompany.com
## 42       Dyan   Oldroyd     7219 Woodfield Rd   Overland Park    KS 66204 913-645-8918          doldroyd@newcompany.com
## 43     Roxane   Campain          1048 Main St       Fairbanks    AK 99708 907-335-6568            roxane@newcompany.com
## 44     Lavera     Perin           678 3rd Ave           Miami    FL 33196 305-995-2078            lperin@newcompany.com
## 45      Erick   Ferencz       20 S Babcock St       Fairbanks    AK 99712 907-227-6777     erick.ferencz@newcompany.com
## 46     Fatima   Saylors      2 Lighthouse Ave         Hopkins    MN 55343 952-479-2375          fsaylors@newcompany.com
## 47       Jina  Briddick       38938 Park Blvd          Boston    MA  2128 617-997-5771     jina_briddick@newcompany.com
## 48    Kanisha   Waycott         5 Tomahawk Dr     Los Angeles    CA 90006 323-315-7314   kanisha_waycott@newcompany.com
## 49    Emerson    Bowley         762 S Main St         Madison    WI 53711 608-658-7940    emerson.bowley@newcompany.com
## 50      Blair     Malet         209 Decker Dr    Philadelphia    PA 19132 215-794-4519            bmalet@newcompany.com
  1. We are now writing the csv file to a file named newcompany.csv and displaying that it has been done successfully. Notice that file paths will have double back slashes for the directory path.
write.csv(AD,"C:\\Users\\FMOF\\Documents\\_Data-Analytics\\newcompany.csv")
print ('CSV file written Successfully :)')
## [1] "CSV file written Successfully :)"
  1. The takeaway…. Sure this process can be done much faster with Notepad++ with a basic search and replace. This was just practice doing things in R that can be used as a document in word, pdf, or made into a webpage of instruction.

.