Issue
I have a .csv list of emails + names. Each name can have 1-3 emails along with it (which are currently separated by a comma). I need to convert this into a .csv list where its 1 name and 1 email.
Here is example:
John Smith,johnsmith1@gmail.com,johnsmith2@gmail.com,johnsmith3@gmail.com
Taylor Smith,taylorsmith@gmail.com
Jack Smith,jacksmith1@gmail.com,jacksmith@gmail.com
...(and there are like 10k more rows)
How can I automatically convert this to:
John Smith,johnsmith1@gmail.com
John Smith,johnsmith2@gmail.com
John Smith,johnsmith3@gmail.com
Taylor Smith,taylorsmith@gmail.com
Jack Smith,jacksmith1@gmail.com
Jack Smith,jacksmith@gmail.com
The main problem here attaching the name to separate rows of the emails that were intially with that name.
I appreciate any help - seems like an easy task, but was stuck on this for few days already, Thanks.
Solution
If you can use Notepad++ here is a two steps solution:
Replace > Options: Check • Regular expressions, Uncheck [ ] .
matches newline
Rearrange line -> Move Name to end of the line
Search for^([^,@\n]+),(.+)\R?
and replace with$2,$1\n
Step 1 > demo at regex101 (explanation on the right side)Now the Name can be captured inside a lookahead and used as a replacement.
Search for([^\n,]++)(?=.*,([^\n,@]+$)),(?:(?1)(?:\n|$))?
and replace with$2,$1\n
Step 2 > demo at regex101Each comma seperated substring gets captured by the first group while the second group captures the Name inside a lookahead and is put before the E-Mail and removed from the end.
After both steps the result should look like your desired outcome. Further info: SO Regex FAQ
Answered By - bobble bubble Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.