Search code examples
stringbatch-filecmd

Separate data in <> with cmd


I have a file with the content as in test.txt file. test.txt it includes strings <string><string><string>.....<string> lots more. There is 1 part containing uid: "text="1000***********" contains 16 numbers. I need to separate them by command line in windows 10. please help me.this code t used but it not working:


@echo off 
for /F "delims=" %%I in ('findstr "1000" "test.txt"') do set "LINE=%%I" & for /F "delims=zxcvbnm,.asdfghjkl;: /><?\qwertyuiop[]-=``'' " %%J in ('cmd /V /C "echo/!LINE:*1000^=1000!"') do echo %%J>C:\Users\ADMIN\Pictures\Regfb\uid.txt`

Solution

  • This Batch file split your file with a huge line into lines ending in >

    @echo off
    setlocal EnableDelayedExpansion
    
    call :SplitFile < test.txt > fields.txt
    goto :EOF
    
    
    :SplitFile
    
    rem Read next chunk
    set "chunk="
    set /P "chunk="
    if not defined chunk goto EndOfFile
    
    rem Split chunk in lines ending in ">"
    for %%n in (^"^
    %Do NOT remove this line%
    ^") do set /P "=!chunk:>=>%%~n!" < NUL
    
    goto SplitFile
    
    :EndOfFile
    echo/
    

    After that, is very easy to process this file with standard Batch commands. For example:

    for /F "tokens=5 delims== " %a in ('findstr "1000" fields.txt') do @echo %~a
    

    Output:

    100084525094698