Create Two New Columns From Data in Single Column

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
aisha
Posts: 26
Joined: 28 Sep 2016 06:40

Create Two New Columns From Data in Single Column

#1 Post by aisha » 03 Jan 2018 14:16

Hello DOSTips list,
We got a request for one that I am really struggling with:
We get lots of TXT files with user name and passwords, one account per line and some character (often a colon) separating the username and password, such as

jack.thehill@domain.com:jack'spassword
jill.thehill@website.com:jill'spassword

We are needing to get the batch to process it so the original displays, followed by a COMMA, followed by the EMAIL ADDRESS, followed by a COMMA, followed by the PASSWORD
jack.thehill@domain.com:jack'spassword,jack.thehill@domain.com,jack'spassword
jill.thehill@website.com:jill'spassword,jill.thehill@website.com,jill'spassword

Since the files could potentially have different characters that separate the EMAIL ADDRESS from the PASSWORD we will probably just need to SET a variable each time we run it, such as:
set separator=: (or possibly set separator=^:) as I cannot remember if the ":" is a special character.

This really has me scratching my head on how to do this, any advice would be greatly appreciated.

Aisha

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Create Two New Columns From Data in Single Column

#2 Post by Squashman » 03 Jan 2018 14:32

Code: Select all

@ECHO OFF
set "delim=:"
FOR /F "tokens=1,2 delims=%delim%" %%G IN (passwords.txt) DO echo %%G%delim%%%H,%%G,%%H
pause
Output

Code: Select all

jack.thehill@domain.com:jack'spassword,jack.thehill@domain.com,jack'spassword
jill.thehill@website.com:jill'spassword,jill.thehill@website.com,jill'spassword

aisha
Posts: 26
Joined: 28 Sep 2016 06:40

Re: Create Two New Columns From Data in Single Column

#3 Post by aisha » 03 Jan 2018 15:29

Squashman - thank you

It works beautifully!!!

Aisha

Post Reply