Home > Blockchain >  How to rearrange this csv email name list
How to rearrange this csv email name list

Time:07-19

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,[email protected],[email protected],[email protected]
Taylor Smith,[email protected]
Jack Smith,[email protected],[email protected]
...(and there are like 10k more rows)

How can I automatically convert this to:

John Smith,[email protected]
John Smith,[email protected]
John Smith,[email protected]
Taylor Smith,[email protected]
Jack Smith,[email protected]
Jack Smith,[email protected]

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.

CodePudding user response:

If you can use Notepad here is a two steps solution:

Replace > Options: Check • Regular expressions, Uncheck [ ] . matches newline

  1. 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)

  2. 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 regex101

    Each 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

CodePudding user response:

bobble bubble's solution is PERFECT and worked !

  • Related