首页 > 代码库 > 批处理提取文字到新文本

批处理提取文字到新文本

从txt文件文件内容xx-ReadLog中提取号码后面的数字到新的文件

 09:35:5220135444

09:35:52  :  读卡完成,送出号码 80135448
09:35:5620135444
09:35:56  :  读卡完成,送出号码 90135944

 

@echo off  
setlocal enabledelayedexpansion  
REM cd /d %~dp0  
cd /d D:\Desktop\sea\aa  
REM ==================代码区==============  
for /f "delims=" %%i in (dir /a-d/b/s *ReadLog*.txt‘) do (  
    set aa=%%i  
    for /f "usebackq tokens=2 delims=送出号码" %%j in ("%%i") do (  
    echo %%j>>c:\zz.txt  
    )  
  
)  
::==================代码区===========================%  
echo 操作已完成!按任意键退出!&pause>nul  
exit/b  
  
  
for /f "delims=" %%i in (dir /a-d/b/s *.txt‘) do (  
    REM for /f "tokens=* delims=送出号码 " %%j in (%%i) do (  
    set aa=%%i  
    echo !aa!  
    REM for /f "usebackq tokens=2" %%j in ("te st.txt") do (  
    REM echo %%j  
    REM )  
    for /f "usebackq tokens=2 delims=送出号码" %%j in ("!aa!") do (  
    echo %%j>>c:\zz.txt  
    )  
    REM echo %%i & pause 

方案2

 

@echo off  
set dir=G:\tt\00  
setlocal EnableDelayedExpansion  
for /f %%i in (dir %dir% /b‘) do (  
    SET a=%%i  
    echo !a!|find "ReadLog"&&(  
        for /f "tokens=1,2,3,4 delims= " %%b in (%dir%\!a!) do echo %%e>>%dir%\temp  
    )     
)  
for /f %%i in (%dir%\temp) do echo %%i|find "ECHO">nul||echo %%i>>z.txt  
del /s/q %dir%\temp>nul  

方案3

 

set dir=G:\tt\00  
  
FOR /f "tokens=4" %%a IN (type "%dir%\*ReadLog.txt" ^|find "送出"‘) DO (  
    ECHO.%%a >>ztest.txt  
      
)  

 

批处理提取文字到新文本