我有一个名为“其中包含”的文本文件file.txt
,
Combo: [email protected]:password
As Combo:
[email protected]:ajfbdf
some text here
some more text here
As Combo: [email protected]:password@1
some random text here
[email protected]:passypassyword123
[email protected]:youtube123
我正在运行下面的代码,仅从mail:pass
上面的文本文件中进行过滤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
预期产出mail.txt
,
[email protected]:ajfbdf
[email protected]:password@1
[email protected]:password
[email protected]:passypassyword123
[email protected]:youtube123
但是,我得到的实际输出是,
[email protected]:ajfbdf
[email protected]:password@1
[email protected]:password
Combo:
Combo:
Combo:
As
As
[email protected]:passypassyword123
[email protected]:youtube123
笔记:邮件 ID 和密码在不同的文本文件中会有所不同。例如,上面给出的邮件 ID 和密码是我随机输入的。
请修复我的代码并帮助获得预期的输出。提前致谢。
答案1
尝试使用这个循环来查找由分隔符和标记决定的条件......
@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 "@")
- 更新-版本灵感来自于
@somebadhat's
回答帖
@rem.^
Combo: [email protected]:password^
As Combo:^
[email protected]:ajfbdf^
some text here^
some more text here^
As Combo: [email protected]:password@1^
some random text here^
[email protected]:passypassyword123^
[email protected]: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
答案2
这里没有太多新内容。我本来会这样写不是我的回答。
@REM Win10 64-bit Pull email address:password from text file using CMD:
@REM Combo: [email protected]:password
@REM some text here
@REM As Combo: [email protected]:password@1
@REM [email protected]: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
或者:
@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