Collapsible line by line

I am trying to parse the output of another function that is output line by line. to understand the function, it returns several lines of the parameter and numbers of the type " top=123456789" or " low=123456789" (without quotes) -

I'm trying to parse strings now

for /F "delims=" %%a in ('%%I ^| findstr top') do set updir=%%1
set "updir=%1:~4%" 
echo. %updir%

I am trying to get pure numbers by trimming well-known keywords like top, which must then be set to var to return ( %~1% ???) to the calling function back (another batch file).

Can someone help me with this please? shure it would be better to crop directly with "=".

UPDATE:

this is the code that returns the lines from the associated script i. I tried several ways to parse the result, but I seem blind or too stupid to see, everything is strange.

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (
rem process the HTML line-by-line

org echo(%%I

try1 (echo %%I|findstr top

try2 for /F "delims=" %%a in ('%%I ^| findstr top') do set updir=%%a
try2 echo. %updir%

try3 for /F "delims=" %%a in ('%%I') do findstr top
try3 echo. %2%


)

doesn't work either

for /F "tokens=1,2delims==" %%a in ('%%I') do if %1 == top set updir=%%b
echo %updir%

delim ( /delims ), .

:

, , :

rem trim whitespace from beginning and end of line
for /f "tokens=*" %%x in ("%%~I") do set "line=%%x"

rem test that trimmed line matches "variable=number"

to find a single item like e.g. "top" you have to add "to" or adjust whole first token
 ! line! | findstr/i "^ to [a-z] = [0-9]" > NUL && (

rem test was successful.  Scrape number.
for /f "tokens=2 delims==" %%x in ("%%I") do set "value=%%x"
echo !value!
)
0
3

, , - , , "text = numbers", , , , :

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (

    rem trim whitespace from beginning and end of line
    for /f "tokens=*" %%x in ("%%~I") do set "line=%%x"

    rem test that trimmed line matches "variable=number"
    echo !line! | findstr /i "^[a-z]*=[0-9]*$" >NUL && (

        rem test was successful.  Scrape number.
        for /f "tokens=2 delims==" %%x in ("%%I") do set "value=%%x"
    )
)

, , . .

, , , , , , HTML. , HTML, HTML , .

0

?

for /F "delims=" %%a in ('type file.txt ^| findstr "top low"') do set /a %%a 

set top
set low
echo %top%, %low%
0

Try the following:

for /F "tokens=2delims==" %%a in ('findstr top file.txt') do set "updir=%%a"
echo.%updir%

According to your comment, my new code is:

@echo off &setlocal enabledelayedexpansion
set "string=%%I"
set "string=!string:*top=!"
for /f "delims== " %%z in ("!string!") do set "string=%%z"
echo !string!

.. conclusion:

123456789

Added

Edit2: ".

0
source

Source: https://habr.com/ru/post/1649418/


All Articles