3

I have a text file named file.txt Which contains,

Combo: testing123mail@gmail.com:password
As Combo: 
abcdefghijklmnopqrstuvwxyz@gmail.com:ajfbdf
some text here
some more text here
As Combo: hadvsfhia@ahfjbadj.com:password@1
some random text here
iloveu@gmail.com:passypassyword123
goldenmammy@hotmail.com:youtube123

I am running the below code, to filter only mail:pass from the above text file file.txt

for /f "tokens=3" %%a in ('type file.txt^|find "As Combo:"') do >>mail.txt echo %%a
for /f "tokens=2" %%b in ('type file.txt^|find "Combo:"') do >>mail.txt echo %%b
for /f "tokens=1" %%c in ('type file.txt^|find ":"') do >>mail.txt echo %%c

Expected Output in mail.txt,

abcdefghijklmnopqrstuvwxyz@gmail.com:ajfbdf
hadvsfhia@ahfjbadj.com:password@1
testing123mail@gmail.com:password
iloveu@gmail.com:passypassyword123
goldenmammy@hotmail.com:youtube123

But, am getting actual output is,

abcdefghijklmnopqrstuvwxyz@gmail.com:ajfbdf
hadvsfhia@ahfjbadj.com:password@1
testing123mail@gmail.com:password
Combo:
Combo:
Combo:
As
As
iloveu@gmail.com:passypassyword123
goldenmammy@hotmail.com:youtube123

Note: The mail id and passwords will be differ in different text file. Above given mail id and passwords are typed by me randomly for example.

Kindly fix my code and help to get expected output. Thanks in advance.

  • please someone help :( – Philip Nov 9 at 6:29
  • I'm not a batch expert, but if you want, I can help you it with a single line in powershell – Danfossi Nov 9 at 12:07
2

Try this loop with find conditioned by delimiters and tokens...

@echo off && setlocal enabledelayedexpansion

set "_log=.\mail.txt" && cmd /v /c cd.>!_log!

for /f "tokens=* delims=" %%i in ('type .\file.txt')do echo/%%~i|find "@" >nul && (
   for /f "tokens=1-3 delims=:" %%I in ('echo/%%~i')do echo/%%~I|find "@" >nul && (
    set "_m_p=%%~I:%%~J")||set "_m_p=%%~J:%%~K")&& for %%E in ("%%~J")do >>!_log! (
      echo/!_m_p: =!|find "@")

  • Update - Version inspired by the @somebadhat's answer post

@rem.^
                Combo: testing123mail@gmail.com:password^
                As Combo:^
                abcdefghijklmnopqrstuvwxyz@gmail.com:ajfbdf^
                some text here^
                some more text here^
                As Combo: hadvsfhia@ahfjbadj.com:password@1^
                some random text here^
                iloveu@gmail.com:passypassyword123^
                goldenmammy@hotmail.com:youtube123

@echo off & type nul >.\mail.txt & for /f "tokens=*delims=" %%i in ('type file.txt')do (
echo=%%~i|find "@">nul && for /f "tokens=01,02,03delims=:" %%I in ('call echo=%%~i')do (
echo=%%~I|find "@">nul && set "_m_p=%%I:%%J" || set "_m_p=%%~J:%%~K") && for /f %%E in ('
echo=%%~J')do cmd /v/c "echo=!_m_p: =!"|find "@")>>.\mail.txt ||>nul call nul 2>nul 2>&1

  • I liked your answer so I played around with it – somebadhat Nov 11 at 1:40
  • give me an example of mixed style – somebadhat Nov 16 at 1:38
  • Your code works. The only improvement you could make to your answer is to explain the logic of the commands. Why is the space in !_m_p: =! so important? I updated my answer. – somebadhat Nov 16 at 11:29
  • REM is better than ::. You will get less failure if you use REM – somebadhat Nov 16 at 11:36
1

There is not much new here. This is how I would have written It Wasn't Me's answer.

@REM Win10 64-bit Pull email address:password from text file using CMD: 
@REM Combo: testing123mail@gmail.com:password
@REM some text here 
@REM As Combo: hadvsfhia@ahfjbadj.com:password@1
@REM goldenmammy@hotmail.com:youtube123
@echo off 
cd.> mail.txt
for /f "tokens=* delims=" %%i in ('type file.txt') do echo %%~i | find "@" >nul && (
for /f "tokens=1-3 delims=:" %%I in ('echo %%~i') do echo %%~I | find "@" >nul && (
set "_m_p=%%I:%%J") || set "_m_p=%%J:%%K") && (
setlocal enableDelayedExpansion
for %%E in ("%%J") do echo !_m_p: =! | find "@">> mail.txt 
)
exit /b

Or:

@echo off & cd.> mail.txt & for /f "tokens=*delims=" %%i in ('type file.txt')do (
echo %%~i|find "@">nul && for /f "tokens=1-3delims=:" %%I in ('echo %%~i')do (
echo %%~I|find "@">nul && set "_m_p=%%I:%%J" || set "_m_p=%%~J:%%~K") && for /f %%E in ('
echo %%~J')do cmd /v/c echo !_m_p: =!|find "@")>> mail.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.